Given an array of intervals of the form [start, end], merge all overlapping intervals and return an array of non-overlapping intervals.
One example is the following array [[1,2], [3,4]]. There is no overlap here. Hence the result is the same as the input. Another example is [[1,2], [1,4]]. They are overlapping and the result is [[1,4]]. If the start number of the next element is the same as the end number of the previous element, the items should be treated as overlapping.
One possible solution is to first sort the items by start element. This can be achieved with an in-place sorting and a lambda expression: intervals.sort(key=lambda item: item[0]).
Given the head of a linked list, remove the nth element from the end of the list and return the head of the list. As a follow-up, this should be done with one iteration.
The most obvious solution is to count the number of elements in the list in one iteration. This is necessary, because we don’t know initially how long the list is. Then iterate over the list again and once the index is reached, set pointer = pointer.next. This way the nth element is skipped.
However, there is a more elegant way to achieve this.
Given an array nums with n colored objects, sort the array in place so that the colors are orders. The colors are represented by the numbers 0, 1, and 2.
The easiest way to achieve this is via quicksort in O(n*log n).
Given a list of ascending sorted numbers, find the first and last occurrence of a target number. For example for the list [1,2,2,3,4] and target = 2, the result would be [1,2]. If the target number is not in the array, return [-1,-1].
Given a list of integers, add three integers at the same time so that the sum of those integers is 0. There should be no repetition of integers, for example [-1, 0, 1] is equivalent to [-1, 1, 0].