# Category: Amazon Questions

## Merge a Linked list into another Linked List at Alternate Positions.

Objective: Given two linked lists, merge one list into another at alternate positions, if second link list has extra nodes, print them as well Example: 5 -> 10 -> 15 -> 20 ->25 ->...

## Print The Top View of a Binary Tree

Objective: – Given a binary tree, print it in Top View of it. What is Top View: Top view means when you look the tree from the top the nodes you will see will...

## Inorder Predecessor and Successor in Binary Search Tree

Objective: – Given a Binary Search Tree, Find predecessor and Successor of a given node. What is Predecessor and Successor : When you do the inorder traversal of a binary tree, the neighbors of...

## Check if Array Contains All Elements Of Some Given Range

Objective: Given an array of unsorted numbers, check if it contains all elements of some given range. Examples: int[] arrA = { 11, 17, 13, 19, 15, 16, 12, 14 }; Range : 12-15...

## Check if Array is Consecutive Integers

Objective: Given a array of unsorted numbers, check if all the numbers in the array are consecutive numbers. Examples: int [] arrA = {21,24,22,26,23,25}; – True (All the integers are consecutive from 21 to...

## In an Array, find the Contiguous Subarray with Sum to a Given Value.

Objective: Given an array and an integer, find the Subarray whose sum is equal to the given integer. Examples: int[] arrA = { 25, 12, 14, 22, 19, 15, 10, 23 }; Integer =...

## Rearrange Positive and Negative Elements at Alternate Positions in an Array In O(1) Extra Space

Objective: Given an array arrA[] which has negative and positive elements, rearrange the array in such a manner that positive and negative elements occupy the alternate positions and if there are extra positive or...

## Find intersection between Two Sorted Arrays.

Objective: Given two sorted arrays, Find intersection point between them. Examples: int[] a = { 1, 2, 3, 6, 8, 10 }; int[] b = { 4, 5, 6, 11, 15, 20 }; Output:...

## Find Kth Smallest or Largest element in an Array.

Objective: Find Kth Smallest or Largest element in an Array Example: int[] arrA = { 2, 3, 11, 16, 27, 4, 15, 9, 8 }; Output: The 4th smallest element is : 8 Approach:...

## Given an array arrA[], find the maximum j – i such that arr[j] > arr[i].

Objective: Given an array arrA[], find the maximum j – i such that arr[j] > arr[i]. Example: int[] arrA = { 12, 3, 1, 5, 6, 4, 10, 9, 8, 0 }; Output: Max(j-i)...

## Find All Elements in an Array which appears more than N/K times, N is Array Size and k is a Number.

Objective: Given an array of size of N and number k. Find all elements in an Array which appears more than N/K times. Input: Array [] and number k. Example: int[] arrA = {...

## Print All The Nodes Which are X distance from the Given Node

Objective: – Given Binary Tree, Print All The Nodes Which are X distance from the Given Node. Example : Approach: Quite Tricky solution, i will explain using the example given in the picture.

## Print All The Nodes Which are X distance from the Leaf Nodes

Objective: – Given Binary Tree, Print All The Nodes Which are X distance from the Leaf Nodes Example : Approach:

## Print All The Nodes Which are X distance from the Root

Objective: – Given Binary Tree, Print all the nodes which are X distance from the root Example : Appraoch:

## Find the Distance between Two Nodes of a Binary Tree.

Objective: – Given nodes in a binary tree, find the distance between them. Example : Approach: