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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:17:56+00:00 2026-05-25T02:17:56+00:00

there was a party.there was a log register in which entry and exit time

  • 0

there was a party.there was a log register in which entry and exit time of all the guests was logged.you have to tell the time at which there was maximum guest in the party.
input will be the entry and exit time of all the n guests [1,4] [2,5] [9,12] [5,9] [5,12]
the output will be t=5 as there was maximum 3 guest were there namly guest(starting from 1) 2,4 and 5.

what i tried so far is

main()
        {
    int ret;
    int a[5]={1,2,9,5,5};
    int b[5]={4,6,12,9,12};
    int i,j;
    int runs=5;
    int cur = 0,p1 = 0,p2 = 0;
    printf("input is ");
    for(i=0;i<5;i++)
    {
        printf("(");
        printf("%d,%d",a[i],b[i]);
        printf(")");

    }

    while(runs--)
    {
        while(p1<5 && p2<5)
        {
            if(a[p1] <= b[p2])
            {
                cur ++;
                p1 ++ ;
            }
            else {
                cur --;
                p2 ++ ;
            }
            ret = cur ;
        }
    }
    printf("\n the output is %d",ret);

        }

i am getting 3 as output..which is completely wrong! where am i making error?

  • 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-25T02:17:57+00:00Added an answer on May 25, 2026 at 2:17 am

    Several things are problematic with your code. Here’s a few pointers on where to improve it:

    • Your algorithm itself is doubtful. Assume that your first guest is the party host and stays from 1 until the end time of the party. With your current code, p2 will never change and you will ignore all other guests’ leave times.

    • Even if your algorithm worked, it would assume that your input is sorted. By iterating p1/p2 you implicitly assume growing times in your array, which is already wrong for your sample input. So you ought to sort the input first.

    • You are assigning the result ret at each iteration of your main loop. This neglects the fact on whether the current state (cur) is the maximum number of guests or not. Hint: If yo are to compute a maximum of something and don’t have any maximum computation in your code, there may be something missing.

    Here’s a different idea: Assuming you can spare an array of size maxtime, create an array filled with 0s. Process your input by increment the array at a certain time, if a guest arrives, and decrement it when a guest leaves. For example, the first 5 minutes would then look like [1, 1, 0, -1, 1, ...]. Then it’s much simpler to walk linearly through the array and compute the maximum prefix sum. It’s also much easier this way to compute the full time-interval for how long this maximum number of guests was present.

    (If you want to go more fancy and have a much larger total time interval to cover, instead rely on a map with times as keys. Initialize like the array, then process the keys in sorted order.)

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

Sidebar

Related Questions

I have a program which utilizes a 3rd party tool to create a log
I have an app which allows users to log in via Facebook, and all
Are there any third-party Templating Engines for Asp.net like we have smarty,savant for php
We have a simple table (an audit log) that our (3rd-party) product fills with
Brief I have an installation package (MSI based) which attempts to register a dll
Is there a third party tool or something similar that will allow users to
Apart from Sql server profiler ,is there any third party user friendly tool available
I use C#, IIS, ASP.NET, SQL Server. Is there a third-party platform I can
Are there any libraries (3rd party or built-in) in PHP to calculate text diffs?
Is there any way (3rd party product or other method) to do a partial

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.