Number of Sublists With Sum of Target - Amazon Top Interview Questions
Given a list of integers nums and an integer target, return the number of sublists whose sum is equal to target. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [2, 0, 2] target = 2 Output 4 Explanation We have these sublists whose sum is 2: [2], [2, 0], [0, 2], [2]
View Solution →Swappable Trees - Amazon Top Interview Questions
Given two trees root0 and root1, return whether you can transform root0 into root1 by swapping any node's left and right subtrees any number of times. Example 1 Input root0 = [1, [3, null, null], [4, [0, null, [2, null, null]], null]] root1 = [1, [3, null, null], [4, [0, null, [2, null, null]], null]] Output True
View Solution →Hit Counter - Amazon Top Interview Questions
Implement a hit counter which keeps track of number of the number of hits in the last 60 seconds. add(int timestamp) which adds timestamp in seconds in the hit counter count(int timestamp) which returns the number of hits that have been made in the last 60 seconds, given the current time is timestamp. You can assume that the timestamps passed into add and count are monotonically increasing. Constraints n ≤ 100,000 where n is the number of calls that are made to add and count Exampl
View Solution →Trie - Amazon Top Interview Questions
Implement a trie data structure with the following methods: Trie() constructs a new instance of a trie add(String word) adds a word into the trie exists(String word) returns whether word exists in the trie startswith(String p) returns whether there's some word whose prefix is p Constraints n ≤ 100,000 where n is the number of calls to add, exists and startswith Example 1 Input methods = ["constructor", "add", "add", "exists", "startswith", "exists"] arguments = [[], ["dog"],
View Solution →Longest Consecutive Sequence - Amazon Top Interview Questions
Given an unsorted array of integers nums, find the length of the longest sequence of consecutive elements. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [100, 4, 200, 1, 3, 2] Output 4 Explanation The longest sequence of consecutive elements is [1, 2, 3, 4]. so we return its length: 4. Example 2 Input nums = [100, 4, 200, 1, 3, 2, 101, 105, 103, 102, 104] Output 6 Explanation The longest sequence of consecutive elem
View Solution →