Array DSA problems in swift.

Find Longest consecutive sequence

[Question]: Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time.Example: I/P = [200,4,2,1,3,100].. Output-> 4 because 1,2,3,4 is largest consecutive. Now a similar problem which gives consecutive array

Leader array questions.

[Question 1] .Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1 Example 1:: Input: arr = [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Explanation: – index 0 –> the greatest element to the right of index 0 is index 1 (18). – index 1 –> …

Leader array questions. Read More »