Tag Archives: TRIE

Print all valid words that are possible using Characters of Array

Given a dictionary and a character array, print all valid words that are possible using characters from the array. Examples: Input : Dict – {“go”,”bat”,”me”,”eat”,”goal”, “boy”, “run”} arr[] = {‘e’,’o’,’b’, ‘a’,’m’,’g’, ‘l’} Output : go, me, goal. Asked In : Microsoft Interview The idea is to use Trie data structure to store dictionary, then search… Read More »

Boggle | Set 2 (Using Trie)

Given a dictionary, a method to do lookup in dictionary and a M x N board where every cell has one character. Find all possible words that can be formed by a sequence of adjacent characters. Note that we can move to any of 8 adjacent characters, but a word should not have multiple instances… Read More »

Weighted Prefix Search

Given n strings and a weight associated with each string. The task is to find the maximum weight of string having the given prefix. Print “-1” if no string is present with given prefix. Examples: Input : s1 = “geeks”, w1 = 15 s2 = “geeksfor”, w2 = 30 s3 = “geeksforgeeks”, w3 = 45… Read More »

Minimum XOR Value Pair

Given an array of integers. Find the pair in an array which has minimum XOR value. Examples: Input : arr[] = {9, 5, 3} Output : 6 All pair with xor value (9 ^ 5) => 12, (5 ^ 3) => 6 , (9 ^ 3) => 10. Minimum XOR value is 6 Input :… Read More »

Construct a unique matrix n x n for an input n

Given an odd integer n, find a matrix of size n x n with following conditions: Each cell contains an integer from 1 and n (inclusive). No integer appears twice in the same row or the same column. All 1’s must be at every possible distance from the center of the matrix. The center of… Read More »