String Vikram
String Vikram
sequence of characters.
1) it consider as data type & array of bytes that store sequence of char => str
2) str => arry of char => str terminated by '\0' = >string ka end batane ke liye ek special character hota hai, jise null character
823
8
traverse the string S and when any string S1 is found as a substring in Finding the Length of String
Replace in String the string S then replace it by S2
Rotations of a String:
Generate all rotations of a given string
Reverse a String:
Trim a String =>
Input: str = “Hello World”
Remove spaces from a given string
Output: dlroW olleH
O(n) O(1)
reverse ( s.begin () , s.end () ) ;
s = string(s.rbegin(), s.rend()); O(n) O(n)
Stack
O(n) O(n)
O(n) O(1)
7. Subsequence of a String => sub-seq => selecting some or all characters in Print all substring of a number without any conversion
the same order, without rearranging them. input: N = 12345
sub-string is a contiguous part of a string Output: Possible Substrings: {1, 12, 123, 1234, 12345, 2, 23, 234, 2345, 3, 34, 345, 4,
n size str => n*( n + 1 ) / 2 => non empt sub-str 45, 5}
n size str => ( 2^n )-1 sub-seq
comparing original and reversed strings – O(n) Time and O(n) Space
Check if actual binary representation of a number is palindrome Reverse actual bits of the given number
Check if two strings are same or not
Length of a String Input: s1 = “abc”, s2 = “abc”
Output: Yes
TC: O(n),
Built-In Methods
String Matching Algorithms => find pattern in given str
approach
Longest Common Prefix using Sorting
sort arr of str -->
Auxiliary Space: O(m) to store the strings first, last and result.
4. Valid Parentheses
22. Generate Parentheses
a-2
question special bec compressed string s should not be returned separately, but instead, be stored in the input character array chars
T.C : O (n)
S.C : O(1)
tc = O( n )
2 traversal
Most ask string q in interview
1) Reverse Words
Using Stack
Time complexity: O(n)
Auxiliary Space: O(n)
Time Complexity: O(n*m*log n), to sort the array, where n is the number of strings and m is the length of longest
string.
Auxiliary Space: O(m) to store the strings first, last and result.
Longest Common Prefix using
Word by Word Matching
Time Complexity : O(n*m), as we are iterating through all the strings and for each string we are iterating though
each characters, where n is number of strings and m is length of the longest string.
Auxiliary Space : O(m), to store the longest prefix string.