iOS

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 »

Rearrange array element by sign

[Question]: An given array contains equal number of positive and negative elements. Without altering the relative order of positive and negative elements, you must return an array of alternately positive and negative values.Example: —Input: {1,2,-4,-5}Output: 1 -4 2 -5 Approach #1 As positive index is on even numbers so create variable named positiveIndex with 0

Rearrange array element by sign Read More »