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 6752349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:02:04+00:00 2026-05-26T13:02:04+00:00

/** * * @param d * currency divisions * @param p * target *

  • 0
/**
 * 
 * @param d
 *            currency divisions
 * @param p
 *            target
 * @return number of coins
 */
public static int change(int[] d, int p) {
    int[] tempArray = new int[p*2]; // tempArray to store set
                                                    // of coins forming
                                                    // answer
    for (int i = 1; i <= p; i++) { // cycling up to the wanted value
        int min = Integer.MAX_VALUE; //assigning current minimum number of coints
        for (int value : d) {//cycling through possible values
            if (value <= i) {
                if (1 + tempArray[i - value] < min) { //if current value is less than min
                    min = 1 + tempArray[1 - value];//assign it
                }
            }
        }
        tempArray[i] = min; //assign min value to array of coins
    }
    return tempArray[p];
}

Can anyone help me see why this is not working please? The method is meant to be given an input of values representing coins, it has an infinite number of these coints with which to form the integer p, the method is to return the minimum number of coins used to get to p.

  • 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-26T13:02:04+00:00Added an answer on May 26, 2026 at 1:02 pm

    tempArray is initialized to 0 on all indices.
    using tempArray[1-value] is basically giving you 0.
    So, all indices from 1 to p has the value 1 + tempArray[1-value]
    This is 1. Also, tempArray[1-value] is a negetive index. I think you meant tempArray[i-value]

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

Sidebar

Related Questions

char *getInput2(char *param) { int data_len; data_len=atoi(getenv(CONTENT_LENGTH)); char input[9]; fgets(input, 9, stdin); return strdup
void some_func(int param = get_default_param_value());
public ActionResult Edit(string param) { } http://localhost/Edit/5,someothervalue,etc How can i reach 'param' from a
I have a situation where the param won't be set, but my attempts to
bool is_something_ok(int param,SomeStruct* p) { bool is_ok = false; // check if is_ok if(is_ok)
I have a class Param.cpp which is a set of parameters for the main
In this example: /** * * @param <type> $foo * @return <type> */ function
public class BaseFoo { private string param; public BaseFoo(string param) { this.param = param;
In my ASP.Net Website I am using String.Format({0:C}, param) to format currency values. On
void func(int* param){}; func(&123); //error: '&' on constant funct(&int(123)) //error

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.