char A[1000]; // creates a character array of size 1000.
char *A = (char *) malloc(1000 * sizeof(char)); // creates a character array of size 1000
A[i]
Strings have to end with a '\0' character.
All C input functions like scanf do it automatically.
Direct string assignments like `char A[20] = "Hello";` does it automatically as well.
strlen(A); // O(n) operation where n is length of string
C style char arrays work in C++ as well. However, C++ provides string which is much more powerful than C arrays. We will be using C++ strings in most of the problems on this judge.
string A; // declares an empty string
string A = "Hello"; // declares string initialized to "Hello".
A[i] // O(1)
A.length() // O(1)
A += "Hello"; // Appends Hello to the string. O(n) operation
A.push_back('H'); // Append character H to the string. O(1) operation.
Java has strings as well which are very similar to C++ string. However java strings are immutable. As such, if you plan to keep appending to the string, then better use StringBuilder.
String A = new String(); // declares an empty string. O(1)
String A = new String("Hello"); // declares string initialized to "Hello"
OR for mutable string :
StringBuilder A = new StringBuilder(); // empty string
StringBuilder A = new StringBuilder("Hello"); // stringbuilder initialized to "Hello".
A.charAt(i) // O(1). Works for both String and StringBuilder
A.length() // O(1) operation
String : A.concat("Hello"); // O(n) operation. Creates another copy of the string as string is immutable.
StringBuilder : A.append("Hello"); // O(l) operation where l is the length of the string being appended. Much more efficient.
Python has string which is very similar to java string. Its immutable.
A = "" # empty string
A = "Hello" # string initialized to "Hello"
A[i] # O(1)
A = A + "Hello" # O(n) operation and a new copy is created
An alternative way if you are going to do a lot of appends :
l = []
l.append('string1')
l.append('string2')
l.append('string3')
A = ''.join(l)
Problem | Score | Companies | Time | Status |
---|---|---|---|---|
Palindrome String | 150 |
|
30:40 | |
Vowel and Consonant Substrings! | 200 |
|
42:19 | |
Remove Consecutive Characters | 200 |
|
42:20 | |
Serialize | 200 |
|
15:22 | |
Deserialize | 200 |
|
23:22 | |
String And Its Frequency | 200 |
|
22:29 | |
Bulls and Cows | 200 |
|
38:08 | |
Self Permutation | 200 |
|
14:21 | |
Longest Common Prefix | 225 |
|
27:45 | |
Count And Say | 250 |
|
43:00 |
Problem | Score | Companies | Time | Status |
---|---|---|---|---|
Amazing Subarrays | 150 |
|
26:39 | |
Implement StrStr | 225 |
|
33:14 | |
Stringoholics | 300 |
|
67:22 |
Problem | Score | Companies | Time | Status |
---|---|---|---|---|
Minimum Characters required to make a String Palindromic | 200 |
|
64:41 | |
Convert to Palindrome | 200 |
|
40:38 | |
Minimum Appends for Palindrome! | 200 |
|
46:12 | |
Minimum Parantheses! | 200 |
|
25:47 | |
Longest Palindromic Substring | 500 |
|
59:51 |
Problem | Score | Companies | Time | Status |
---|---|---|---|---|
Salutes | 200 |
|
23:48 | |
Integer To Roman | 250 |
|
42:10 | |
Roman To Integer | 250 |
|
33:02 | |
Add Binary Strings | 300 |
|
40:40 | |
Power of 2 | 350 |
|
63:26 | |
Multiply Strings | 375 |
|
65:00 |
Problem | Score | Companies | Time | Status |
---|---|---|---|---|
Convert the amount in number to words | 200 |
|
36:15 | |
Compare Version Numbers | 225 |
|
67:12 | |
Atoi | 250 |
|
52:19 | |
Valid Ip Addresses | 250 |
|
68:37 |
Problem | Score | Companies | Time | Status |
---|---|---|---|---|
Length of Last Word | 225 |
|
17:54 | |
Reverse the String | 250 |
|
36:31 |
Problem | Score | Companies | Time | Status |
---|---|---|---|---|
Zigzag String | 300 |
|
52:40 | |
Justified Text | 300 |
|
79:17 | |
Pretty Json | 400 |
|
64:47 |