What is the difference between RANK() and DENSE_RANK()?
Data Engineer
CREATE TABLE orders ( driver_id varchar, city varchar, order_id varchar ); -- Get the top 10 drivers by number of orders in each city.
Where is data compression more effective — in columnar or row storage, and why?
Tell me what you know about columnar and row-based data storage. When and which one should be chosen and why?
-- Original table stretch -- It is necessary to fill NULLs in the order of id with the previous non-NULL value - perform a downward fill id | ttime | val ---|-------|----- 1 | 07:30 | NULL 1 | 09:21 | 10 1 | 13:53 | NULL 1 | 16:12 | NULL 2 | 09:42 | 133 2 | 15:20 | NULL 2 | 21:33 | NULL 3 | 08:01 | NULL 3 | 11:41 | 8 3 | 14:23 | NULL 3 | 16:17 | NULL 3 | 19:54 | 2 4 | 13:10 | 312 4 | 14:42 | NULL 4 | 16:31 | 7 4 | 17:44 | NULL id | ttime | val ---|-------|----- 1 | 07:30 | NULL 1 | 09:21 | 10 1 | 13:53 | 10 1 | 16:12 | 10 2 | 09:42 | 133 2 | 15:20 | 133 2 | 21:33 | 133 3 | 08:01 | NULL 3 | 11:41 | 8 3 | 14:23 | 8 3 | 16:17 | 8 3 | 19:54 | 2 4 | 13:10 | 312 4 | 14:42 | 312 4 | 16:31 | 7 4 | 17:44 | 7 -- On the left is the original table, and on the right is what needs to be obtained SELECT id, ttime, COALESCE(val, LAST_VALUE(val) OVER(PARTITION BY id ORDER BY ttime)) as val FROM stretch
How much additional memory does a solution with a dictionary require, excluding the returned data?
Assess the final solution in terms of time and memory.
How long does a solution using the built-in sorted function take? Can a faster solution be devised?
How to solve the problem in linear time O(n) using a dictionary? What should be stored in the dictionary to then assemble a sorted string? How to handle characters that are not in the order?
-- Find all passengers who traveled for two or more consecutive days.
Given a string order specifying the desired order of characters. It is required to rearrange the characters in the string unsorted_str so that the order is consistent with the string order. Both strings consist of lowercase English alphabet characters, and all characters in the order string are distinct. The order of characters in unsorted_str is considered consistent with the order string if, whenever character x appears before character y in order, any occurrence of x in unsorted_str must be before any occurrence of y. Situations where order does not contain characters from unsorted_str and vice versa are permissible. Return any valid permutation. unsorted_str = "abcd" order = "cba" answer = "dcba" ("cdba", "cbda", "cbad") def CustomSort(unsorted_str: str, order: str) -> str: # code here
How to perform an upward fill (fill NULLs with the previous non-null value in reverse order)?