# Tagged: Strings

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

Objec­tive: Print All N Length Strings from Given String of Length K where char­ac­ters can appear mul­ti­ple time. Exam­ple: String k = “ALGO” N=2 Result: AA LA GA OA AL LL GL OL AG LG

## Print All N Length Strings from Given Number K

Objec­tive: Given Num­ber K, Print all the strings of N length. Exam­ple: N = 2, K = 3 [1, 1] [2, 1] [3, 1] [1, 2] [2, 2] [3, 2] [1, 3] [2, 3]…

## The Word Break Problem

Objec­tive : Given an string and a dic­tio­nary of words, find out if the input string can be bro­ken into a space-separated sequence of one or more dic­tio­nary words. Exam­ple: dic­tio­nary = [“I” , “have”,…

## Sort Names by their Last Names.

Objec­tive: Given a list of names ( first name and last name), sort the list by their last names. Exam­ple: List [] = {“Daen­erys Tar­garyen”, “Jon Snow”, ” Tyrion Lan­nis­ter”, ” Jof­frey Baratheon”} Out­put: [Joffrey…

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

Objec­tive: — Given “n”, gen­er­ate all valid paren­the­sis strings of length “2n”. Exam­ple: Given n=2 Out­put: (()) ()() Approach:

## Generate All Strings of n bits.

Objec­tive: — Gen­er­ate All Strings of n bits, con­sider A[0..n-1] is an array of size n. Exam­ple : n = 3 Out­put: [0, 0, 0]    [1, 0, 0]    [0, 1, 0]    [1, 1, 0] [0,…

## Print All The Permutations Of a String

Objec­tive: Given a String, print all the per­mu­ta­tions of it. Input: A String Out­put: Print all the per­mu­ta­tions of a string Exam­ple: Input : abc Out­put: abc acb bac bca cba cab Approach:

## Check if one string is Rotation of another string

Objec­tive: Write an algo­rithm to check if one string is Rota­tion of another string. This ques­tion has been asked in the Ama­zon inter­view. Exam­ple: Input Strings : ‘sum­it­jain’ and ‘tjain­sumi’ Out­put : true Input…

## String Compression using count of repeated characters — Run Length Encoding

Objec­tive: Write an algo­rithm to com­press the given string by using the count of repeated char­ac­ters and if new com­pressed string length is not smaller than the orig­i­nal string then return the orig­i­nal string.…

## Replace all spaces in a String with ‘%20′

Objec­tive: Write an algo­rithm to replace all spaces in a given string with ‘%20′. You can con­sider that string has enough space at the end of the string to hold the extra char­ac­ters. Input:…

## Find Whether Two Strings are Permutation of each other

Objec­tive: Given Two Strings, check whether one string is per­mu­ta­tion of other Input: Two Strings Out­put: True or false based on whether strings are per­mu­ta­tion of other or not. Exam­ple: “sumit” and “tiums” are per­mu­ta­tions of…

## Find The Longest Sequence Of Prefix Shared By All The Words In A String

Objec­tive: Write an algo­rithm to find The Longest Sequence Of Pre­fix Shared By All The Words In A String. This inter­est­ing prob­lem was asked in the Google inter­view for soft­ware engi­neer. This prob­lem is…

## Find Whether Given Sequence of parentheses are well formed.

Objec­tive: You have been asked to Write an algo­rithm to find Whether Given the Sequence of paren­the­ses are well formed. This ques­tion was asked in the Ama­zon Inter­view. Input: A String con­tains a sequence…

## Find Whether Given String is palindrome or Not.

Objec­tive : Write an algo­rithm to find Whether Given String is palin­drome or Not. Input:  A String, Out­put: true or false on whether string is palin­drome or not Approach: Use recur­sive approach Com­pare first and last…