Coding Problem Practice
-
In a given word find the first un-repeated letter, e.g., in ‘total’ its ‘o’ and in ‘ teeter’ its ‘r’.
import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; /** * @author mohit * * In a given word find the first un-repeated letter, e.g., in ‘total’ its ‘o’ and in ‘ teeter’…
-
Reverse the LinkedList
public class ReverseLinkedList { private static class SinglyLinkedList { Node head; // prints content of double linked list void printList(Node node) { while (node != null) {…
-
Shortest Path in Matrix Problem Java solution
import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class ShortestPathMatrix { Set elements = new HashSet<>(); Map locationMap = new HashMap<>();…
-
Union Of Two Sorted Array problem or Merge two sorted arrays
import java.util.Arrays; public class UnionOfTwoSortedArray { public static void main(String[] args) { int [] arr1 = {1,3,4,5,7}; int [] arr2 = {2,3,5,6}; int i = arr1.length; int j = arr2.length;…
-
Untraceable ransom note
A kidnapper wrote a ransom note but is worried it will be traced back to him. He found a magazine and wants to know if he can cut out whole words from it and use them to create an untraceable replica…
-
Program to print column names of excel eg. a, b ... ab, ac ... az, ba ... azz, caa
def incrementString(str1): arr = list(str1) arr.reverse() if ord(arr[0]) - ord('a') + 1 == 26: arr[0] = 'a' if str1[:-1] is not '': str1 = incrementString(str1[:-1]) else: str1 = 'a' str1 = str1 +…
-
Find Nth Max or Largest element of unsorted array
arr = [7,2,1,3,10,4,5,8,9,6] nthMax = 2 #specify max element here maxArr = arr for i in range (0, len(maxArr)): for j in range (i, len(maxArr)): if (maxArr[i] k){ q.poll(); } } return (int)q.peek();…
-
Recursively remove all adjacent duplicates
problem url http://www.geeksforgeeks.org/recursively-remove-adjacent-duplicates-given-string/ Input: azxxzy Output: ay First "azxxzy" is reduced to "azzy". The string "azzy" contains duplicates, so…
-
Level Order Tree Traversal or breadth first traversal for the tree.
'' input tree 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ''' class Node: pass root = Node() root.data = 1 root.left = Node() root.right = Node() root.left.data = 2 root.left.left = Node() root.left.right =…
-
Find height of tree
''' input tree 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ''' class Node: pass root = Node() root.data = 1 root.left = Node() root.right = Node() root.left.data = 2 root.left.left = Node() root.left.right =…
-
Producer Consumer Problem
// Java program to implement solution of producer // consumer problem. import java.util.LinkedList; public class Threadexample { public static void main(String[] args) throws InterruptedException {…
-
Print a Binary Tree in Vertical Order
# method have used hashmap class Node: pass root = Node() root.data = 1 root.left = Node() root.right = Node() root.left.data = 2 root.left.left = Node() root.left.right = Node() root.right.data = 3…
-
How HashMap / HashTable works
How HashMap / HashTable works
-
Data Structures: Heaps
Data Structures: Heaps
-
Data Structures: Trees
Data Structures: Trees
-
Data Structures: Tries
Data Structures: Tries
-
Find The Cost (Nested Approch)
Let's say the building has 'n' floors, each fllor has meeting rooms & work-stations, each room has several objects (table, chairs, tv..). Find the cost of perticular room, complete floor or a…
-
A program to check if a binary tree is BST or not
A program to check if a binary tree is BST or not http://www.geeksforgeeks.org/a-program-to-check-if-a-binary-tree-is-bst-or-not/
-
Tree Traversals (Inorder, Preorder and Postorder)
Tree Traversals (Inorder, Preorder and Postorder) http://www.geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/
-
Search in a row wise and column wise sorted matrix
Search in a row wise and column wise sorted matrix www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/
-
LRU Cache (Java)
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of the key if…
-
Remove Nth Node From End of List (Java)
Given a linked list, remove the nth node from the end of list and return its head. For example, given linked list 1->2->3->4->5 and n = 2, the result is 1->2->3->5. Java Solution 1 - Naive Two Passes…
-
Linked List Cycle Detect
Given a linked list, determine if it has a cycle in it. Analysis If we have 2 pointers - fast and slow. It is guaranteed that the fast one will meet the slow one if there exists a circle. The problem…
-
Money Transfer Operation Program
Write java program to perform a money transfer operation for a bank, which is multi-threaded and can run parallel with multi-processor machines Solution can be developed with cachedthreadpool and…
-
Subset Sum Problem
Given a set of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum. Examples: set[] = {3, 34, 4, 12, 5, 2}, sum = 9 Output: True…
-
API to handel navigation of web browser
Design an API to handle the navigation history of a web browser (previous page, next page, list the 10 previous pages), and that can be reusable in many parts of the application (here I give concrete…
-
Sort a file with huge volume of data given memory constraint
Points: We process thousands of flat files in a day, concurrently. Memory constraint is a major issue. We use thread for each file process. We don't sort by columns. Each line (record) in the file is…