- Aggregated Pivot Table
- Bit Shifting
- Bitwise XOR
- Calculate Tick Size
- Collapsing Dictionaries
- Graphs - Breadth First Search
- Graphs - Depth First Search
- Graphs - Detecting Cycles
- Greatest Common Divisor
- Identity Matrix
- Least Common Multiple
- Log Parser
- Nanosleep
- One Hot Encoding
- Parent Child ID Mapping
- Slippage
- Split Training and Testing Sets
- Stratified Sampling
- Symbol Column Update
- Table Indexing
- Word Count
Longest Streak
Question: A streak is the consecutive reoccurance of an event. For example, if you flip a coin twice and it appears head both times, then there is a streak of two heads. Define a function 'streak' that returns the length of the longest streak of a list, as an integer.
Example
q)streak `h`t`h`t`h`h`h`t`t`h`t
3
q)streak ()
0
Solution
######## solution.q ########
streak:{max deltas where differ[x],1b}
Explanation: A streak ends when the subsequent element is different than the current one. We get the streak-ending positions by using the keyword differ on the list. A 1b is appended to the list afterwards to account for the last element so their streak is not short by 1. The streaks are the differences in each pair of ending positions, because the streaks occur in-between. The keyword deltas computes this and then we return the max.