Challenge - 5 Problems
String Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this string indexing code?
Consider the following TypeScript code that accesses characters in a string by index. What will be printed?
DSA Typescript
const text = "hello"; console.log(text[1]);
Attempts:
2 left
💡 Hint
Remember that string indexing starts at 0.
✗ Incorrect
Strings in TypeScript can be accessed like arrays of characters. The index 1 corresponds to the second character, which is 'e' in "hello".
🧠 Conceptual
intermediateWhy is a string considered a data structure?
Which of the following best explains why strings are considered data structures and not just plain text?
Attempts:
2 left
💡 Hint
Think about how you can access parts of a string.
✗ Incorrect
Strings are data structures because they organize characters in a sequence and support operations like indexing, slicing, and length checking.
❓ Predict Output
advancedWhat is the output after string concatenation and length check?
Look at this TypeScript code that concatenates strings and checks length. What will be the output?
DSA Typescript
let s1 = "abc"; let s2 = "def"; let s3 = s1 + s2; console.log(s3.length);
Attempts:
2 left
💡 Hint
Count the total characters after joining.
✗ Incorrect
Concatenating "abc" and "def" results in "abcdef" which has 6 characters.
🔧 Debug
advancedWhat error does this string mutation code cause?
This TypeScript code tries to change a character in a string. What error or output will it produce?
DSA Typescript
let s = "hello"; s[0] = "H"; console.log(s);
Attempts:
2 left
💡 Hint
Strings are immutable in TypeScript.
✗ Incorrect
Strings cannot be changed character by character. The assignment to s[0] does nothing, so s remains "hello".
🚀 Application
expertHow many unique characters are in this string?
Given the string "banana", how many unique characters does it contain?
Attempts:
2 left
💡 Hint
Count distinct letters only once.
✗ Incorrect
The string "banana" contains the characters 'b', 'a', and 'n'. These are 3 unique characters.
