String Equivalence Relations - Amazon Top Interview Questions
You are given three lowercase alphabet strings a, b and target. Strings a and b have the same length and are defined to be equivalent: a[i] = b[i]. For example, if a = "abc" and b = "xyz", then "a" = "x", "b" = "y" and "c" = "z". Also, we can make the following kinds of inferences for characters: c = c a = b implies b = a a = b and b = c implies a = c Return the smallest lexicographically equivalent string for target. Constraints n ≤ 1,000 where n is the length of a and b m ≤ 1
View Solution →Middle Operable Deque - Amazon Top Interview Questions
Implement a data structure with the following methods: void appendLeft(int val) when appends val to the left of the deque. int popLeft() which pops the leftmost value of the deque. If it's empty, return -1. void append(int val) when appends val to the end of the deque. int pop() which pops the last value of the deque. If it's empty, return -1. void appendMiddle(int val) when appends val to the middle of the deque. int popMiddle() which pops the middle value of the deque. If it'
View Solution →Circular Queue - Amazon Top Interview Questions
Implement a circular queue with the following methods: CircularQueue(int capacity) which creates an instance of a circular queue with size capacity. Circular queues are implemented using an array which holds the enqueued values with pointers pointing to the start and end of the queue. When the queue reaches the end of the array, it will start to fill items from the start of the array if they were dequeued. boolean enqueue(int val) which adds val to the queue if it has space. If the que
View Solution →Largest Sum of Non-Adjacent Numbers in Circular List - Amazon Top Interview Questions
You are given a list of integers nums representing a circular list (the first and the last elements are adjacent). Return the largest sum of non-adjacent numbers. Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [9, 2, 3, 5] Output 12 Explanation We can take 9 and 3. Note that we can't take 9 and 5 since they are adjacent.
View Solution →Largest K Sublist Sum - Amazon Top Interview Questions
You are given a list of integers nums, and an integer k, which represents a large list of nums concatenated k times. Return the sum of the sublist with the largest sum. The sublist can be empty. Constraints 0 ≤ n ≤ 100,000 where n is the length of nums. 0 ≤ k ≤ 10,000 Example 1 Input nums = [1, 3, 4, -5] k = 1 Output 8 Explanation We can take the sublist [1, 3, 4] Example 2 Input nums = [1, 3, 4, -5] k = 2 Output 11 Explanation We can take the s
View Solution →