# Tagged: Strings

## Minimum Copy Paste Operations

Objective: You have given a character ‘A’ which is already printed. You are allowed to perform only 2 operations – Copy All – This operation will copy all the printed characters. Paste – This...

## Print all sub sequences of a given String

Objec­tive:  Given a String write an algorithm to print all the possible sub subsequences. Example: String input = “abc”; Output: Possible sub sequences – {Empty}, {a}, {b}, {c}, {ab} ,{a,c}, {b, c}, {a, b, c}...

## Print all substrings of a given string

Objec­tive:  Given a string write an algorithm to print all the possible sub strings. Example: String input = “abcd”; Output: Possible sub strings – a          a b      a b c   a b c b         ...

## Text Justification Problem

Objec­tive:  Given a list of words and length L. Format the words so that each line will have only L characters and fully justified (left and right justified). Restrictions- You need to fit as many...

## Remove the duplicates from the given String

Objective:  Given a string, write an algorithm to remove the duplicate characters in that string. Example: Input: tutorialhorizon Output: tuorialhzn Approaches: There are multiple approaches to solve this problem- Use Sorting – (Will change the...

## Dynamic Programming — Longest Palindromic Subsequence

Objective: Given a string, find a longest palindromic subsequence in it. What is Longest Palindromic Subsequence: A longest palindromic subsequence is a sequence that appears in the same relative order, but not necessarily contiguous(not...

## All N Length Strings from Given String of Length K

Objective: Print All N Length Strings from Given String of Length K where characters can appear multiple time. Example: String k = “ALGO” N=2 Result: AA LA GA OA AL LL GL OL AG...

## Print All N Length Strings from Given Number K

Objective: Given Number K, Print all the strings of N length. Example: N = 2, K = 3 [1, 1] [2, 1] [3, 1] [1, 2] [2, 2] [3, 2] [1, 3] [2, 3]...

## The Word Break Problem

Objective : Given an string and a dictionary of words, find out if the input string can be broken into a space-separated sequence of one or more dictionary words. Example: dictionary = [“I” ,...

## Sort Names by their Last Names.

Objective: Given a list of names ( first name and last name), sort the list by their last names. Example: List [] = {“Daenerys Targaryen”, “Jon Snow”, ” Tyrion Lannister”, ” Joffrey Baratheon”} Output:...

## Find All the Well Ordered Permutations of a Given String.

Objective: Write an algorithm to Print All the Well Ordered Permutations of a Given String. What is Well Ordered String: When all the alphabets in a string occur in the increasing order irrespective of...

## Print All Possible Valid Combinations Of Parenthesis of Given ‘N’

Objec­tive: – Given “n”, generate all valid parenthesis strings of length “2n”. Example: Given n=2 Output: (()) ()() Approach:

## Generate All Strings of n bits.

Objec­tive: – Generate All Strings of n bits, consider A[0..n-1] is an array of size n. Example : n = 3 Output: [0, 0, 0]    [1, 0, 0]    [0, 1, 0]    [1, 1, 0]...

## Print All The Permutations Of a String

Objective: Given a String, print all the permutations of it. Input: A String Output: Print all the permutations of a string Example: Input : abc Output: abc acb bac bca cba cab Approach:

## Check if one string is Rotation of another string

Objective: Write an algorithm to check if one string is Rotation of another string. This question has been asked in the Amazon interview. Example: Input Strings : ‘sumitjain’ and ‘tjainsumi’ Output : true Input...