Reverse String
Use slicing with a step of -1 for the shortest solution, or iterate from the end if the interviewer wants the mechanics.
Write a function that returns the input string reversed.
All revision cards
Use slicing with a step of -1 for the shortest solution, or iterate from the end if the interviewer wants the mechanics.
Write a function that returns the input string reversed.
Normalize k by array length, then rebuild the order from the tail slice followed by the front slice.
Rotate an array to the right by k positions.
Store indices in a deque so values stay in decreasing order. Remove indices that fall out of the window and pop smaller trailing values before appending the current index.
Return the maximum value in each sliding window of size k.
Keep a running prefix sum and a hash map of how many times each prefix sum has appeared. For each new prefix, look for prefix minus k to count matching earlier starts.
Count how many contiguous subarrays sum to k.
Build a frequency map, then select the top k items by count using a heap-based helper or a bucket sort approach.
Return the k most frequent values from an integer list.
Store each seen number in a dictionary keyed by value. For each new number, check whether target minus number has already appeared.
Return the indices of two numbers that add up to a target.
Start with one pointer at the left and one at the right. Move the left pointer rightward when the sum is too small and the right pointer leftward when the sum is too large.
Given a sorted array, return the indices of two numbers that add up to a target.
Convert both arrays to sets, take the union, and sort the result if stable output is helpful.
Return the unique values that appear in either array.
Push opening brackets onto a stack and pop when you see a matching closer. Any mismatch or leftover opening bracket means the string is invalid.
Check whether brackets in a string are balanced and properly nested.