Category: Top Companies

4

Find the Maximum Depth OR Height of a Binary Tree

Objective: Given a binary tree, find the height of it Input: A Binary Tree Output: Height of a binary tree Example: Approach:

4

Add two numbers represented by a linked list, Numbers are Stored in FORWARD order

This post is the extension of   – Two numbers represented by a linked list, Number Stored in REVERSE order Objective: Two numbers represented by a linked listwhere each node contains single digit. The digits...

2

Add two numbers represented by a linked list, Numbers are Stored in REVERSE order

We have similar post – Two numbers represented by a linked list, Number Stored in FORWARD order Objective: Two numbers represented by a linked list where each node contains single digit. The digits are...

0

Reverse the binary representation of a number.

Objective: Write a program to Reverse the binary representation of a number Example: Input : 30 Output : 15 Explanation: binary representation of 30 is : 11110 reverse of binary representation : 01111 decimal...

0

Reverse a Linked List – Part 2

This post is the extension of our earlier post Reverse a linked list. Here We have provided the better recursive solution in which we start reversing the list from the end. Objective: Reverse the...

1

Swap Every Kth Node in a LinkedList

Objective: Given a linked list, swap every kth node in that. If at the end of the list remaining nodes are less than k, leave them untouched. Input: A linked list, A number k....

0

Delete a Node in the Middle of a linked list, Given only access to that Node

Objective: Write a program to Delete a Node in the Middle of a linked list, Given only access to that Node Example: Original List : ->1->2->8->3->7->0->4 After Deleting the mid node (say 7) :...

1

Find the n’th Node from the end of a given Linked List

Objective: Given a linked list and integer ‘n’, write an algorithm to find the nth node from the end in the Linked List. Example: Original List : ->1->2->8->3->7->0->4 Output : 3rd Element from the...

10

Remove Duplicates from an Unsorted Linked list

Objective: Write a program to remove the duplicates from an unsorted linked list Example: Input Linked List : 1->2->2->4->3->3->2 Output : 1->2->4->3 Input: An unsorted linked list Output: Linked list with no duplicates. Approach:...

3

Check if one string is Rotation of another string

Objective: Write an algorithm to check if one string is Rotation of another string. This question has been asked in the Amazon interview. Example: Input Strings : ‘sumitjain’ and ‘tjainsumi’ Output : true Input...

0

String Compression using count of repeated characters – Run Length Encoding

Objective: Write an algorithm to compress the given string by using the count of repeated characters and if new compressed string length is not smaller than the original string then return the original string....

0

Replace all spaces in a String with ‘%20’

Objective: Write an algorithm to replace all spaces in a given string with ‘%20’. You can consider that string has enough space at the end of the string to hold the extra characters. Input:...

0

Find Whether Two Strings are Permutation of each other

Objective: Given Two Strings, check whether one string is permutation of other Input: Two Strings Output: True or false based on whether strings are permutation of other or not. Example: “sumit” and “tiums” are...

1

Find Intersection Point in Two Linked List

Objective: Given Two linked list, check whether both list intersect each other, if yes then find the starting node of the intersection. Intersection point means end of one linked list is linked with some...

%d bloggers like this: