Amazon Interview Experience | Set 425

Round 1: Technical Face 2 Face.

  1. Write a program to find the range of majority elements in array(non-descending)?
  2. Write program to print all the permutation of String? Example Input : AB, Output : {$, “A”, “B”, “AB”};
  3. Write program to transform a tree from give tree, such that each node will have the sum of child nodes plus itself.(Write recursive funciton)

To best of me i have given answer to all the three programs(little doubtful with 2nd one).

No Selected. 🙁

For first question my approach was:

filter_none

edit
close

play_arrow

link
brightness_4
code

public class MajorityRange {
  
    public static void main(String args[])
    {
        int number[] = { 1, 3, 3, 3, 3, 3, 4 };
        int size = number.length;
        int start = 0;
        int end = size - 1;
        int count = 1;
        for (int i = 1; i < size; i++) {
            if (number[i] != number[i - 1]) {
                if (count > size / 2) {
                    end = i - 1;
                }
                else {
                    start = i;
                }
            }
            else {
                count++;
            }
        }
        System.out.println("Start = " + start + "End = " + end);
    }
}

chevron_right


Explanation: Solved in O(n) time complexity. In order to improve the complexity we can use divide and conquer strategy(Modified version of Jump Search or interpolation Search)

Write your Interview Experience or mail it to contribute@geeksforgeeks.org



My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.