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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:03:07+00:00 2026-06-10T23:03:07+00:00

The problem statement is here https://www.interviewstreet.com/challenges/dashboard/#problem/4fe12e4cbb829 You are distributing candy among children. All the

  • 0

The problem statement is here https://www.interviewstreet.com/challenges/dashboard/#problem/4fe12e4cbb829

You are distributing candy among children. All the children sit in a line and each of
them  has a rating score according to his or her usual performance. Each child gets 
at least 1 piece. Children get jealous of their immediate neighbors, so if two 
children sit next to each other then the one with the higher rating must get 
more candies. You wants to save money, so minimize the total number of candies.

Input: A file with the children's ratings, 1 per line.

And my code is working for small input sizes but for a very large input its either not giving any output ( on the interview.com console) or deviating from the answer by a small amount on my system.
What cold be the error in my code?

#include <stdio.h>

int main() 
{
    int i, j, n, rating[100000], candy[1000000], total = 0;

    scanf("%d", &n);

    for (i=0 ; i < n; i++) 
    {
        scanf("%d",&rating[i]);
        candy[i] = 1;
    }

    for (i=0 ; i < n+1 ; i++)
    {
      for (j=1 ; j < n-1; j++)
      {
          if( rating[j-1] < rating[j] )
          {
              if ( candy[j-1] >= candy[j] )
                  candy[j]++;
          }

          if( rating[j+1] < rating[j] )
          {
              if ( candy[j+1] >= candy[j] )
                  candy[j]++;
          }       
      }  
    }

    for (i=0 ; i < n ; i++)
        total = total + candy[i];

    printf("%d",total);

    return 0;
}
  • 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-06-10T23:03:09+00:00Added an answer on June 10, 2026 at 11:03 pm

    You might be running into one of the translation limits of your implementation with the automatic arrays rating and candy. Try placing them at file scope, i.e. outside of main. Then they have static storage duration. Most systems allow much larger static objects than automatic objects.

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

Sidebar

Related Questions

Here is the problem statement: Calling a setter on the object should result in
Problem statement: Find the right triangle that has integers for all sides and all
I'm working on a Clojure algorithm to solve the problem posed here: http://spin.atomicobject.com/2011/05/31/use-clojure-to-move-drugs-a-programming-challenge/ and
I've got a weird problem: both my if and else statements are executing. Here's
Problem Statement is : Given 2 Dimensional array, print output for example If 4
Problem statement We have one employer that wants to interview N people, and therefore
Problem Statement: I'm creating a template for multi tiered complicated calculations in MS Excel
Problem statement: It is necessary for me to write a code, whether which before
I'm having some problem with this statement declare @result int select @result = (select
I have a problem with a continue statement in my C# Foreach loop. I

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.