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

 

jebbert@volusia.k12.fl.us > test2021_04_29_P1SLHL_countMatches
prev  |  next  |  chance

Write a method that returns the number of times 'target' appears in 'str', but with no overlaps allowed. For example, "aaa" appears THREE times in "aaaaaaaaa". Once you use the first three characters as a match, you cannot use any of those again or you would have overlap. Look at the test data for further examples.


test2021_04_29_P1SLHL_countMatches("amanaplanacanalpanama", "an") → 4
test2021_04_29_P1SLHL_countMatches("rrrrrrrrrrrrrrrrrrrrrrrrrr", "rr") → 13
test2021_04_29_P1SLHL_countMatches("no overlap is allowed", "not here") → 0

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

public int test2021_04_29_P1SLHL_countMatches(String str, String target) { }

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: 250

Copyright Nick Parlante 2017 - privacy