Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5933341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:57:35+00:00 2026-05-22T14:57:35+00:00

I have an array of numbers nums[] and target such that it satisfies the

  • 0

I have an array of numbers nums[] and target such that it satisfies the below condition
{{nums[],target}

 1> {{8, 2, 2, 1},12} --> returns true       
 2> {{8, 2, 2, 1},9}  --> returns true        

 1 condition> identical adjacent values with a subset of remaining numbers sum to target (or)
 2 condition> identical adjacent values are not chosen such that subset of other numbers sum to target. 
so that in this example 
1> 8+2+2 = 12.
2> 8+1=9.

how do i handle the above 2 conditions in Java.

EDITED FOR DANTE:
Expected This Run
groupSumClump(0, {2, 4, 8}, 10) → true true OK
groupSumClump(0, {1, 2, 4, 8, 1}, 14) → true true OK
groupSumClump(0, {2, 4, 4, 8}, 14) → false false OK
groupSumClump(0, {8, 2, 2, 1}, 9) → true false X
groupSumClump(0, {8, 2, 2, 1}, 11) → false false OK
groupSumClump(0, {1}, 1) → true false X
groupSumClump(0, {9}, 1) → false false OK
other tests false X

*Code for Dante:
http://www.ideone.com/xz7ll

@Dante,Please check the above link,it fails for test scenarios mentioned.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:57:36+00:00Added an answer on May 22, 2026 at 2:57 pm

    I’ve seen you struggling with this question for a long time, so, here are some codes….

    EDITed

        int nums_another[] = new int [nums.length];
        int i = 0;
        int j = 0;
        i++;
        int c = 1;
        while (i < nums.length){
            if (nums[i] == nums[i-1]) { // count identical numbers
                c++;
            }
            else { // not identical, store sum of previous identical numbers (possibly only 1 number)
                if (nums[i-1] != 0) {
                    nums_another[j] = nums[i-1] * c;
                    j++;
                }
                c = 1;
            }
            i++;
        }
        if (nums[i-1] != 0) { // store last
            nums_another [j] = nums[i-1] * c; 
        }
    

    Now nums_another includes:

    • the sums of the groups of the adjacent identical numbers (in your case 4 = 2 + 2)

    • not identical numbers (in your case 8, 1)

    • 0’s at last (thus in all 8 4 1 0)


    By the way, the problem with your code is that:

    because you set the next identical number to 0 immediately, it will fail for 3 or more,

    for example, 8 2 2 2 1 -> 8 4 0 2 1 instead of -> 8 6 0 0 1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have an array numbers that contains the following values: int numbers
i have a array that returns some numbers. and i want to add those
Newbie asking for help: I have an array of numbers that needs to be
I have an Array of Arrays that contains numbers in a particular order. I
I have an array of numbers that can be 1-24. ($timelist) I want to
I have an array of numbers that potentially have up to 8 decimal places
I have an array of numbers and dynamically adding new numbers to that array
I have an array of numbers. I can print all values using for each
I have an array of numbers and I'd like to create another array that
I have an array of numbers , say nums[n] . I have to find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.