Solve three coding tasks: binary search, tree path, subarray
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Onsite
Solve the following coding tasks:
1) In a sorted array, every value appears exactly twice except for one value that appears once. Find the single value in O(log n) time and O(
1) extra space using a binary-search-based approach.
2) Given the root of an N-ary tree and a sequence of integers representing a path, determine whether this path exists in the tree. Each node may have multiple children and values are not guaranteed to be unique. A valid path must start from the root but does not need to end at a leaf node. Return true/false and analyze time and space complexity.
3) Given two integer arrays, compute the maximum length of a contiguous subarray that appears in both arrays. Discuss multiple approaches (e.g., dynamic programming; binary search on length with rolling hash) and their time/space trade-offs.
Quick Answer: This set of problems evaluates algorithmic problem-solving across binary search for identifying a unique element in a sorted array, N-ary tree traversal and path matching with non-unique node values, and array algorithms for finding the longest common contiguous subarray.