countClumps challenge


I am working on below challenge

Say that a "clump" in an array is a series of 2 or more adjacent elements of the same value. Return the number of clumps in the given array.

countClumps([1, 2, 2, 3, 4, 4]) → 2
countClumps([1, 1, 2, 1, 1]) → 2
countClumps([1, 1, 1, 1, 1]) → 1

i am not clear on the description of the challenge. please advise
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gerwin Jansen, EE MVETopic Advisor Commented:
gudii9 - where are you from, what is your native language?
Gerwin Jansen, EE MVETopic Advisor Commented:
You have to count blocks of the same numbers.

1 1 1 2 3 3 4 5 contains 2 blocks (numbers 1 and numbers 3)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
countClumps([1, 2, 2, 3, 4, 4]) → 2//this is clear as it has one 2's clump and one other 4's clump
countClumps([1, 1, 2, 1, 1]) → 2//this is clear
countClumps([1, 1, 1, 1, 1]) → 1//how it is 1?
is it because it has one clump of 5 1's in it?
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Gerwin Jansen, EE MVETopic Advisor Commented:
Yes, one clump of 1's
gudii9Author Commented:
public int countClumps(int[] nums) {
  int counter=0;
  boolean flag=false;
  for(int i=0;i<nums.length-1;i++){
    else if(nums[i]!=nums[i+1]){
  return counter;

Open in new window

above passes all tests.
basically checking i with i+1  and making flag to true and repeat in if loop then in else check for inequality and make flag false there
gudii9Author Commented:
just thinking any other possible simple solutions/approaches for this? or any improvements, modifications, optimization to my code above?
Gerwin Jansen, EE MVETopic Advisor Commented:
Can't think of an easier way, if you want a different way then you have to write different pseudo code first. But it works and passes the tests so you've learned some here right?
gudii9Author Commented:
yes definitely
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.