id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

frew@mclean.com > removeNegs
prev  |  next  |  chance

Use a breadth first search to change all negatives to positives in the array. Start by adding the indices of all positive values to the queue. Then for each index, you can change its left and right neighbors to be positive and enqueue them.


removeNegs([14, 20, -29, -10, -10, -28, 9, 12]) → [14, 20, 29, 10, 10, 28, 9, 12]
removeNegs([2, -21, -2, 26]) → [2, 21, 2, 26]
removeNegs([-2, -21, -2, 26]) → [2, 21, 2, 26]

...Save, Compile, Run (ctrl-enter)

public int[] removeNegs(int[] nums) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 300

Copyright Nick Parlante 2017 - privacy