iOS Dev India
Learn
Roadmap
Skills
Swift DSA
Build
Studio
Sandbox
Tools
Agent Skills
Community
Communities
Events
Library
Articles
Resources
Jobs
Create Profile
Home
Learn
Roadmap
Skills
Swift DSA
Build
Studio
Sandbox
Tools
Agent Skills
Community
Communities
Events
Library
Articles
Resources
Jobs
Create Profile
Challenges
/
Count Spaces
·
Step 19/100 · Sets & Hashing
← Count Vowels
Capitalize Word →
Description
Hint
Count Spaces
L1
Easy
Strings
Concept
Comparing characters against a specific one like
" "
is how you count a single kind of character.
Return the number of space characters (
" "
) in
s
.
Examples
▸
s = "a b c"
→ 2
▸
s = "no"
→ 0
▸
s = ""
→ 0
Progressive Hints
Hint 1 · Nudge
You're hunting for exactly one kind of character.
Hint 2 · Plan
Loop over the string and increment a counter each time a character equals a space. Return the counter.
Hint 3 · Approach
count = 0. For each c in s: if c == a space then count = count + 1. Return count.
Reveal the next hint
All hints are out. Take a breath and give it a shot.
Swift
Java
Solution.swift
Tests.swift (Read Only)
Run
Output
// Run your code to see the output here.
Press
ESC
to close.
Start typing to search...