How would you like to learn today?
Visualize algorithms in real time, explore them step by step, or challenge yourself with a test.Choose a path to focusโor scroll down to preview all options.
Visualize the algorithm step-by-step with interactive animations in real time.
Read the full explanation, examples, and starter code at your own pace.
Drag and arrange the algorithm steps in the correct execution order.
๐ง Select Active to activate
Follow every state change, comparison, and transformation as the execution unfolds in real time.
๐ Select Passive to activate
Difficulty: Easy
Topics: Strings, Brute Force, Searching
You are given a list of words.
๐ Your task is to find: Which words are contained inside another word in the same list?
In other words:
Think of each word as a pattern.
Now ask: ๐ "Does this pattern exist inside any other word?"
Example:
So both should be included.
For every word:
If yes โ add it to result
w1 in the array:
w2w1 is found inside w2:
w1 to resultThis problem becomes much clearer when visualized:
๐ Using DrawToCode, you can:
import java.util.*;
public class Main {
public static List<String> stringMatching(String[] words) {
List<String> result = new ArrayList<>();
for (int i = 0; i < words.length; i++) {
for (int j = 0; j < words.length; j++) {
if (i != j && words[j].contains(words[i])) {
result.add(words[i]);
break;
}
}
}
return result;
}
}
Time Complexity: O(nยฒ * m)
(n = number of words, m = average length of words)
Space Complexity: O(1) (excluding output list)
words = ["mass", "as", "hero", "superhero"]
๐ Output:
["as", "hero"]
words = ["blue", "green", "bu"]
๐ Output:
[]
This problem helps you understand:
๐ Once you visualize string overlaps, these problems become much easier to solve
โ Written by Saurabh Patil โข B.Tech CSE โข Software Developer๐ฏ Select Challenge to activate
Drag and arrange the algorithm steps in the correct execution order instead of spending time typing code letter by letter.
The algorithm is divided into three logical parts. Carefully rearrange each section in the correct order to form a complete and valid solution.
Understand Below AlgorithmGreen text means the instruction is placed in the correct position.
Red text means the instruction is in the wrong position.
Instructions with the same background color indicate particular blocks start and end.
A tick mark means the instruction is correct and locked.
๐ Locked steps cannot be moved. Only unlocked steps are draggable.
๐ Enable sound for swap feedback and completion effects.