Amazon.com

  www.amazon.com
Work in HR? Unlock Free Profile

Amazon.com Software Engineer Intern Interview Question

I interviewed in Seattle, WA and was asked:
"In-place array reversal, level-order binary tree traversal, reading two files and outputting strings common to both."
Add Tags [?]
Answer

Part of a Software Engineer Intern Interview Review - one of 4,681 Amazon.com Interview Reviews

Answers & Comments

0
of 0
votes

In Place reverse array:

    public char[] inPlaceReverse(String s) {
        char[] array = s.toCharArray();

        if (s != null) {
            int p1 = 0;
            int p2 = s.length()-1;

            while (p2 - p1 > 0) {
                swap(array,p2,p1);
                p2--;
                p1++;
            }
        }
        return array;
    }

    private void swap(char[] array, int p1, int p2) {
        char temp = array[p1];
        array[p1] = array[p2];
        array[p2] = temp;
    }

- Juan on Feb 4, 2014

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.