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

 

sameNeighbors


Given a rectangular 2d ArrayList of String, count how many of the values have all neighbors equal to them. Neighbors are all adjacent values (up/down/left/right) If the value is on the edge, out of bounds values do not count against this. (corners have 2 neighbors, sides have 3 neighbors, all others have 4 neighbors) Note: It helps to arrange the 2D arraylists in rows so you can visually see the examples.


sameNeighbors([["a", "a", "a"], ["a", "a", "a"], ["a", "a", "a"], ["a", "a", "a"]]) → 12
sameNeighbors([["a", "a", "a"], ["a", "A", "a"], ["a", "a", "a"], ["a", "a", "a"]]) → 7
sameNeighbors([["a", "a", "b"], ["a", "a", "b"], ["a", "a", "b"]]) → 3

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

public int sameNeighbors(ArrayList<ArrayList<String>> grid){ }

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

Copyright Nick Parlante 2017 - privacy