# Category: Amazon Questions

## Track the Maximum Element in a Stack.

Objective: In a Stack, keep track of maximum value in it. It might be the top element in the stack but once it is poped out, the maximum value should be from the rest...

## Print All Possible Valid Combinations Of Parenthesis of Given ‘N’

Objec­tive: – Given “n”, generate all valid parenthesis strings of length “2n”. Example: Given n=2 Output: (()) ()() Approach:

## Implement Queue Using Stacks

Objective: We know that Queue is FIFO (First-in-First-Out) and Stack is LIFO ( Last-in-First-Out). Here our objective is to implement queue using stacks. Approach: Take 2 Stacks, stack1 and stack2. stack1 will be used...

## Alternate Splitting of a given Linked List

Objective: Given a singly linked list, split it into two linked lists. These linked lists will contain the alternate nodes from the given linked list. Example:

## Reverse The Doubly Linked List

Objective: Reverse The Doubly Linked List. Example: Approach: Every Node in a doubly linked list has next and previous pointer. Do the linear traversal of the linked list and keep swapping the next and...

## Swap Kth Node from the front with the Kth Node from the End

Objective: Given a Linked List and a number k, Swap Kth Node from the front with the Kth Node from the End Example: ->10->20->30->40->50->60->70 Swapping 1 Node from the Front and from the End...

## Print the Bottom View of the Binary Tree.

Objec­tive: – Given a binary tree, print it in Bottom View of it. What is Bottom View: Bottom view means when you look the tree from the bottom the nodes you will see will be...

## Delete X Nodes After Y Nodes In a Linked List

Objective: Given a Linked List and x and y. Delete x number of nodes after y nodes from the start. Example: ->10->20->30->40->50->60->70->80->90->100->110->120 Deleted 4 Nodes after 5 Nodes ->10->20->30->40->50->100->110->120 Approach: We need two pointers....

## 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...