Find all subset of string in dictionary – code

find all subset string

Find all subset of string in dictionary is to find the subset of an input string that exists in dictionary. The dictionary contains one million words. For this question, the trick is to find subset, not substring. The difference between substring and subset is: The substring is contiguous sequence of …

Continue reading

Domino Eulerian path problem using backtracking

dominoes euler path

A Euler path (Eulerian path) is a path in a graph that you visit each edge exactly once. You can visit the same vertex multiple times though. Dominoes is one example of finding Euler path problem. A domino is a game piece that has 2 numbers on it, one number …

Continue reading

Modulo operation and circular array

modulo operation

The modulo operation returns the remainder of one number divided by another. Modulo operator is a arithmetical operator, represented as %. One modulo operation example in math, 6 % 4 is 2. The modulo operation is also used in circular array. When an array index modulo (or mod) the array …

Continue reading

Last men standing using circular linked list

last men standing

The “Last man standing” is also called “Josephus problem” or “circle of death problem”. Given a number n people standing in a circle, eliminate every kth one until the last one remain. This problem can be solved with circular linked list. First, we build a circular Linked List by adding …

Continue reading

Detect cycle and remove cycle in directed graph

detect graph cycle

A graph is a data structure that consists of a set of nodes (vertices) connected by edges. A graph is cyclic if the graph comprises a path that starts from a node and ends at the same node. In this post, a simplified solution is provided to detect cycle and …

Continue reading

Get suggested friends (2 solutions) – DFS and Union Find

suggested friends

Get suggested friends is one of a coding question in social network applications. The data structures for social network is usually a graph. In the graph, you can use depth first search(DFS) or breadth first search(BFS) to find the connections between people. Alternatively, you can also use Union find to …

Continue reading

Tell friends story by timestamp – DFS in weighted graph

tell friends story

In the post of Get suggest friends, we provide solution of DFS in unweighted graph. This post is Tell friends story, using DFS in weighted graph. An individual person is a node. Between two people there is an undirected edge because they are mutual friends. When one person tells another …

Continue reading

Autocorrect with trie and edit distance in Java

autocorrect java

Google provides a powerful autocorrect for validating the keywords we type into the input text box. It checks against a dictionary. If it doesn’t find the keyword in the dictionary, it suggests a most likely replacement. To do this it associates with every word in the dictionary a frequency, the …

Continue reading

Web scraping in Java – Jsoup and selenium

web scraping feature

Web scraping is a great way to retrieve data and save the information. with a simple Java web scraping setup, you can download content using Jsoup and selenium. Download the source code from the GitHub. Table of Content Web scraping and parsing in HTML – Jsoup Download images – Jsoup …

Continue reading

Find a random number NOT in array – code

find random not in array

Find random number not in array is a tricky question. It is pretty straight forward to find a random element in array by getting an random index within the range. If you are asked to find a random element that is NOT in array, your brain might not response quickly …

Continue reading