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 Positive Numbers
·
Step 2/100 · Hello Arrays
← Sum of Even Numbers
Largest Element →
Description
Hint
Count Positive Numbers
L1
Easy
Arrays & Hashing
Concept
A comparison inside a loop lets you count only the items that satisfy a condition.
0
and negatives are not positive.
Count how many integers in
nums
are strictly greater than
0
. A number like
0
itself does not count.
Examples
▸
nums = [1, -2, 3, 0]
→ 2
▸
nums = [-5]
→ 0
▸
nums = []
→ 0
Progressive Hints
Hint 1 · Nudge
Decide what counts and what doesn't, then only tally the ones that count.
Hint 2 · Plan
Create a counter set to 0. Loop over the array; each time a value is strictly greater than 0, increase the counter. Return the counter.
Hint 3 · Approach
count = 0. For each n: if n > 0 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...