diff --git a/strings/BreakWordsIntoDictionary.java b/strings/BreakWordsIntoDictionary.java index b540961..107045f 100644 --- a/strings/BreakWordsIntoDictionary.java +++ b/strings/BreakWordsIntoDictionary.java @@ -1,6 +1,21 @@ // Question: https://www.geeksforgeeks.org/word-break-problem-using-backtracking/ /* This problem has been solved using the backtracking approach. This removes * extra branches/calls and avoids them which are unnecessary. + * + * Test Cases + * Consider the following dictionary + * { i, like, sam, sung, samsung, mobile, ice, + * and, cream, icecream, man, go, mango} + * + * Input: "ilikesamsungmobile" + * Output: i like sam sung mobile + * i like samsung mobile + * + * Input: "ilikeicecreamandmango" + * Output: i like ice cream and man go + * i like ice cream and mango + * i like icecream and man go + * i like icecream and mango */ import java.util.HashMap; import java.util.ArrayList; diff --git a/strings/LengthOfLongestSubstring.java b/strings/LengthOfLongestSubstring.java index 09fe5f3..84e4f09 100644 --- a/strings/LengthOfLongestSubstring.java +++ b/strings/LengthOfLongestSubstring.java @@ -1,8 +1,22 @@ /* Question: -Program to find- -1.the length of longest substring which does not have any repeated characters. -2.the length of longest substring which has all characters in alphabetical order -Print answer as per user's choice + * Program to find- + * 1.the length of longest substring which does not have any repeated characters. + * 2.the length of longest substring which has all characters in alphabetical order + * Print answer as per user's choice + * + * Test Cases for Problem 1 + * Input: “ABDEFGABEF” + * Output: 6 for “BDEFGA” or “DEFGAB” + * + * Input: "BBBB" + * Outout: 1 for "B" + * + * Test Cases for Problem 2 + * Input: “abcabcdefabc” + * Output: 6 for "abcdef" + * + * Input: “zabcd” + * Output: 5 */ import java.io.*; diff --git a/strings/Permute.java b/strings/Permute.java index 103065b..7c300b1 100644 --- a/strings/Permute.java +++ b/strings/Permute.java @@ -1,4 +1,9 @@ /* URL: https://practice.geeksforgeeks.org/problems/permutations-of-a-given-string/0/?ref=self + * Input: ABC + * Output: ABC ACB BAC BCA CAB CBA + * + * Input: ABSG + * Output: ABGS ABSG AGBS AGSB ASBG ASGB BAGS BASG BGAS BGSA BSAG BSGA GABS GASB GBAS GBSA GSAB GSBA SABG SAGB SBAG SBGA SGAB SGBA */ package strings; diff --git a/strings/README.md b/strings/README.md index 67f27bb..fcf5d05 100644 --- a/strings/README.md +++ b/strings/README.md @@ -4,7 +4,7 @@ The list of problems which can come under a broad heading of problem solving are inserted here. # List of Problems -- Longest Uniform String +- [Longest Uniform String](LongestUniformString.java) Given a string, return the position and length of the substring which has largest number of repeatable characters in the string. @@ -16,12 +16,12 @@ inserted here. Since, the largest substring with same characters is "111" which starts at position 0 and length of the substring is 3. In case of a tie between substrings, return the left most substring as shown in the second example. -- Break Word Problem +- [Break Word Problem](BreakWordsIntoDictionary.java) This is a problem where given a dictionary of words, and an input string, you have to figure out if the string can be split into words present in the dictionary only. If yes, then print the words separated by space or new line. It should also print all the possible sentences the input string can be split into. -- Length of Longest Substring +- [Length of Longest Substring](LengthOfLongestSubstring.java) In this problem, we are performing two tasks 1.the length of longest substring which does not have any repeated characters. @@ -30,14 +30,14 @@ inserted here. The answer is printed as per user's choice. -- Permute String +- [Permute String](Permute.java) This problem finds and prints all the permutations of a given string taken as input from user. -- String Subsequence +- [String Subsequence](StringSubsequence.java) Given two strings, check if the first string can be formed by removing some (or none) of the characters of the second string -- Remove Character +- [Remove Character](RemoveCharacter.java) Remove all ocurrences of a given character from a string. Code contains both recursive and iterative approach diff --git a/strings/RemoveCharacter.java b/strings/RemoveCharacter.java index 1f4f5c0..dcd9b1f 100644 --- a/strings/RemoveCharacter.java +++ b/strings/RemoveCharacter.java @@ -1,4 +1,11 @@ // Remove a character from a string recursively/iteratively. +/* Link to the Problem: https://www.geeksforgeeks.org/remove-all-occurrences-of-a-character-in-a-string-recursive-approach/ + * Test Cases + * Input: text = “firebreather”, ch = ‘e’ + * Output: firbrathr + * Input: text = "Mississippi", ch = ‘s’ + * Output: Miiippi + */ public class RemoveCharacter { public static void removeCharacterIter(String text, char ch) { diff --git a/strings/StringSubsequence.java b/strings/StringSubsequence.java index 8bc4c00..d8c1e20 100644 --- a/strings/StringSubsequence.java +++ b/strings/StringSubsequence.java @@ -1,3 +1,19 @@ +/* Problem Statement: Given two strings check if one can be formed by removing characters from second + * Input : first = geeks, second = geekforgeeks + * Output : Yes + * Here, string2 can be formed from string1. + * + * Input : first = and, second = geekforgeeks + * Output : No + * Here string2 cannot be formed from string1. + * + * Input : first = geeeek, second = geekforgeeks + * Output : Yes + * Here string2 can be formed from string1 + * as string1 contains 'e' comes 4 times in + * string2 which is present in string1. + */ + import java.util.Scanner; class StringSubsequence {