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

Spread the post

Replace every element with the largest element on right side

Given an array of integers values. Write an efficient program to replace every element with the largest element on right side.

Example

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

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

Explanation

Program for Replace every element in largest node on right side. Time complexity O(n).

Output

View process.

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

View steps of execution

Submit your solution in comment section.

Spread the post

Recommended Posts: