Showing posts with label Data Structures. Show all posts
Showing posts with label Data Structures. Show all posts

Friday, August 5, 2016

Almost sorted interval - Hacker Rank Solution

Shik loves sorted intervals. But currently he does not have enough time to sort all the numbers. So he decided to use Almost sorted intervals. An Almost sorted interval is a consecutive subsequence in a sequence which satisfies the following property:

Burger Happiness - Hacker Rank Solution

In Burger Town new burger restaurants will be opened! Concretely,  restaurants will open in  days, while restaurant  will be opened on day  and will be located at . The town should be imagined as an one dimensional line in which every object's location can be described by the  coordinate.

Roy and alpha-beta trees - Hacker Rank Solution

Roy has taken a liking to the Binary Search Trees(BST). He is interested in knowing the number of ways an array  of integers can be arranged to form a BST. Thus, he tries a few combinations, and notes down the numbers at the odd levels and the numbers at the even levels.

Coloring Tree - - Hacker Rank Solution

You are given a tree with N nodes with every node being colored. A color is represented by an integer ranging from 1 to 109. Can you find the number of distinct colors available in a subtree rooted at the node s?

Cube Summation - - Hacker Rank Solution

You are given a 3-D Matrix in which each block contains 0 initially. The first block is defined by the coordinate (1,1,1) and the last block is defined by the coordinate (N,N,N). There are two types of queries.

Wednesday, June 29, 2016

Truck Tour- Hacker Rank Solution

Suppose there is a circle. There are petrol pumps on that circle. Petrol pumps are numbered to (both inclusive). You have two pieces of information corresponding to each of the petrol pump: (1) the amount of petrol that particular petrol pump will give, and (2) the distance from that petrol pump to the next petrol pump.

Wednesday, March 23, 2016

Insert a node into a sorted doubly linked list - Hacker Rank Solution

 
You’re given the pointer to the head node of a sorted doubly linked list and an integer to insert into the list. Create a node and insert it into the appropriate position in the list. The head node might be NULL to indicate that the list is empty.

Thursday, February 4, 2016

Diagonal Difference - Hacker Rank Solution

Given a square matrix of size N×N, calculate the absolute difference between the sums of its diagonals.
Input Format
The first line contains a single integer, N. The next N lines denote the matrix's rows, with each line

Thursday, January 14, 2016

Swap Nodes [Algo] - Hacker Rank Solution

A binary tree is a tree which is characterized by any one of the following properties:
  • It can be an empty (null).
  • It contains a root node and two subtrees, left subtree and right subtree. These subtrees are also binary tree.

Binary Search Tree : Lowest Common Ancestor - Hacker Rank Solution

You are given pointer to the root of the binary search tree and two values v1 and v2. You need to return the lowest common ancestor (LCA) of v1 and v2 in the binary search tree. You only need to complete the function.

Tree: Huffman Decoding - Hacker Rank Solution

Huffman coding assigns variable length codewords to fixed length input characters based on their frequencies. More frequent characters are assigned shorter codewords and less frequent characters are

Binary Search Tree : Insertion - Hacker Rank Solution

You are given a pointer to the root of a binary search tree and a value to be inserted into the tree. Insert this value into its appropriate position in the binary search tree and return the root of the updated binary tree. You just have to complete the function.

Tree: Height of a binary tree - Hacker Rank Solution

The height of a binary tree is the number of nodes on the largest path from root to any leaf. You are given a pointer to the root of a binary tree. Return the height of the tree.

Tree: Inorder Traversal - Hacker Rank Solution

You are given a pointer to the root of a binary tree; print the values in in-order traversal.
You only have to complete the function.

Tree: Postorder Traversal - Hacker Rank Solution

You are given a pointer to the root of a binary tree; print the values in post-order traversal.
You only have to complete the function.

Tree: Preorder Traversal - Hacker Rank Solution

You are given a pointer to the root of a binary tree; print the values in preorder traversal.
You only have to complete the function.

Reverse a doubly linked list - Hacker Rank Solution

You’re given the pointer to the head node of a doubly linked list. Reverse the order of the nodes in the list. The head node might be NULL to indicate that the list is empty.

Find Merge Point of Two Lists - Hacker Rank Solution

You’re given the pointer to the head nodes of two linked lists that merge together at some node. Find the node at which this merger happens. The two head nodes will be different and neither will be NULL.

Detect Cycle - Hacker Rank Solution

You’re given the pointer to the head node of a linked list. Find whether the list contains any cycle (or loop). A linked list is said to contain cycle if any node is re-visited while traversing the list. The head pointer given may be null meaning that the list is empty.

Delete duplicate-value nodes from a sorted linked list - Hacker Rank Solution

You're given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete as few nodes as possible so that the list does not contain any value more than once. The given head pointer may be null indicating that the list is empty.
Powered by Blogger.