LeetcodeDay 22
LeetcodeDay 22
PseudoCode:-
Approach 1:
// Iterate through the first k words and append them to the StringBuilder
for i = 0 to k-1:
truncatedSentence.append(wordsArray[i]).append(" ")
Approach 2:
// Iterate through the string until reaching k spaces or end of the string
while idx < length(s) AND spaceCount < k:
if s[idx] == ' ':
spaceCount++
idx++
PseudoCode:-
Approach 1:
Approach 2:
// Update the 'rods' array by turning on the respective bit based on the ring position and
color
count = 0
for i in rods:
if i == 131138:
count++
return count
- Time Complexity: O(N)
PseudoCode:-