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
/
Flip Signs
·
Step 8/100 · Hello Arrays
← Last Element
Digit Sum →
Description
Hint
Flip Signs
L1
Easy
Arrays & Hashing
Concept
Building a new array from an existing one is a two-step habit: create an empty result, then append one transformed value per source element.
Return a new array where every integer in
nums
is negated: positive values become negative and negative values become positive.
0
stays
0
.
Examples
▸
nums = [1, -2, 3]
→ [-1, 2, -3]
▸
nums = [0, 5, -5]
→ [0, -5, 5]
▸
nums = []
→ []
Progressive Hints
Hint 1 · Nudge
Every value just trades its sign. Zero is its own opposite, so it stays put.
Hint 2 · Plan
Create an empty result array. For each element, append its negation. Return the result array.
Hint 3 · Approach
result = []. For each n: append -n to result. Return result.
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...