Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions strings/BreakWordsIntoDictionary.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
22 changes: 18 additions & 4 deletions strings/LengthOfLongestSubstring.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down
5 changes: 5 additions & 0 deletions strings/Permute.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
12 changes: 6 additions & 6 deletions strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
7 changes: 7 additions & 0 deletions strings/RemoveCharacter.java
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions strings/StringSubsequence.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down