Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Replace every element with the largest element on left side

Given an array of integers values. Write an efficient program (algorithm) to replace every element with the largest element on left side.
Recommended to view how to Replace every element with the largest element on right side .

Example

Suppose array contain following nodes. view input and accepted output.

Beforemainarray [0] 3 [1] 5 [2] 1 [3] 9 [4] 2 [5] 0size (int) =6 Aftermainarray [0] -1 [1] 3 [2] 5 [3] 5 [4] 9 [5] 9size (int) =6

Explanation

Program for Rreplace every element with largest elements on left side in array. Time complexity O(n).

Output

View process.

Stack Areamainarray [0] -1 [1] 3 [2] 5 [3] 5 [4] 9 [5] 9size (int) =6r_left_mostarray(pointer)auxiliary (int) =0index (int) =3max (int) =9size (int) =6

View steps of execution

Submit your solution in comment section.

Spread the post

Recommended Posts: