# Amazon Programming Interview Questions

### Determine if the sum of two integers is equal to the given value

Given an array of integers and a value, determine if there are any two integers in the array whose sum is equal to the given value. Return true if the sum exists and return false if it does not. Consider this array and the target sums: %0 node_1592256164418 5 node_1592256069696 7 node_1592256107658 1 node_1592256151353 2 node_1 8 node_2 4 node_3 3 %0 node_1 Target Sum node_2 10 node_3 7+3=10, 2+8=10 %0 node_1 Target Sum node_2 19 node_3 No 2 values sum up to 19

Runtime Complexity: Linear, O(n)O(n)O(n)

Memory Complexity: Linear, O(n)O(n)O(n)

You can use the following algorithm to find a pair that add up to the target (say `val`).

• Scan the whole array once and store visited elements in a hash set.
• During `scan`, for every element `e` in the array, we check if `val - e` is present in the hash set i.e. `val - e` is already visited.
• If `val - e` is found in the hash set, it means there is a pair (`e`, `val - e`) in array whose sum is equal to the given `val`.
• If we have exhausted all elements in the array and didn’t find any such pair, the function will return `false`
• Given a Binary Tree, figure out whether it’s a Binary Search Tree. In a binary search tree, each node’s key value is smaller than the key value of all nodes in the right subtree, and are greater than the key values of all nodes in the left subtree i.e. L < N < R.

## 14 Most Popular Amazon Coding Interview Questions

### Amazon Coding Interview Questions on Strings

Strings are a popular data type used to represent text characters. Below are some Amazon coding interview questions on Strings to help you prepare for your Amazon tech interview:Â

• Given: String S Task: Check if it is palindrome or not
• Given: Two strings a and b consisting of lowercase charactersTask: Write a code to check whether the two strings are anagrams of each other
• Given: String S Task: Check if characters of the given string can be rearranged to form a palindromeÂ
• Given: String strTask: Convert the first letter of each word in the string to uppercase
• Given: String str containing only lower case alphabetsTask: Sort it in lexicographically-descending order
• Given: Two strings, S1 and S2 Task: Write a program to merge them alternatively â the first character of S1 with the first character of S2, and so on â till the end of the string
• Given: String S containing alphanumeric charactersTask: Find out whether the string is a palindrome or not
• Given: String STask: Reverse the string without reversing its individual words
• Task: Write a code to implement the function strstr. The function essentially takes two strings as arguments (s,x) and locates the occurrence of the string X in the string SÂ
• Given: Two strings A and BTask: Find if A is a subsequence of B
• Given: Two strings s1 and s2Task: Write a code to check if s2 is a rotated version of the string s1
• Given: Two strings of lowercase alphabets and a value K Task: Write a program function that tells if the two strings are K-anagrams of each other
• Given: Two strings A and BTask: Find the characters that are not common in the two strings
• Given: A string S consisting of lowercase Latin lettersTask: Find the first non-repeating character in S
• Given: A string S Task: Find the length of the longest substring with all distinct characters
• Given: A string,Task: Find the longest substring that is a palindrome in linear time O(N).
• Given: A decimal number m Task: Convert it into a binary string and apply n iterations. In each iteration, 0 becomes 01, and 1 becomes 10. Find the kth (1-indexing) character in the string after nth iteration
• Given: Two binary strings A and B consisting of only 0s and 1sTask: Find the resultant string after adding the two strings
• Given: Two numbers as strings s1 and s2Task: Calculate their product
• Given: Two binary strings A and BTask: Find the product of two strings in decimal value