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

  • Home
  • SEARCH
  • 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 9228203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:15:55+00:00 2026-06-18T05:15:55+00:00

Possible Duplicate: algorthim to solve find max no at a time We are given

  • 0

Possible Duplicate:
algorthim to solve find max no at a time

We are given an array of 2n integers wherein each pair in this array of integers represents the year of birth and the year of death of a dinosaurs respectively. The range of valid years we want to consider is [-100000 to 2005]. For example, if the input was:

-80000 -79950 20 70 22 60 58 65 1950 2004

it would mean that the first dinosaur had a birth year of –80000 and an year of death of –79950 respectively. Similarly the second dinosaur lived from 20 to 70 and so on and so forth.

We would like to know the largest number of dinosaurs that were ever alive at one time. Write a method to compute this, given the above array of 2n integers.

Here’s what I’ve tried so far:

#include<stdio.h>
#include<stdlib.h>
#include <stddef.h>

static void insertion_sort(int *a, const size_t n) 
{
    size_t i, j;
    int value;
    for (i = 1; i < n; i++) {
        value = a[i];
        for (j = i; j > 0 && value < a[j - 1]; j--) {
            a[j] = a[j - 1];
        }
        a[j] = value;
    }
}

int  main(){
    int arr[10]={-80000,-79950,20,70,22,60,58,65,1950,2004};
    int strt[5],end[5];
    int bal[5];
    int i,j,k,l,m,length;
    l=0;
    m=0;

    for (i=0; i<10; i++){
        //printf("i = %2d arr[i] = %2d\n", i, arr[i]);
        if(i%2==0) {
            strt[l]=arr[i];
            l++;
        } else {
            end[m]=arr[i];
            m++;
        }
    }

    insertion_sort(strt, sizeof strt / sizeof strt[0]);
    insertion_sort(end, sizeof end / sizeof end[0]);
    k=sizeof(end)/sizeof(int);

    for(j=0;j<5;j++) {
        bal[i]=strt[i]-end[k-1];
        k--;
    }
    length=sizeof bal / sizeof bal[0];
    insertion_sort(bal, sizeof bal / sizeof bal[0]);
    printf("answer is = %2d",bal[length-1]);
}
  • 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-18T05:15:57+00:00Added an answer on June 18, 2026 at 5:15 am

    I would do something like:

    1. create a map to hold the data
    2. read in a pair
    3. For i = pair.first to pair.second ++map[i]
    4. if there are more pairs, repeat from 2
    5. Find the element in the map with the largest count. The key for that element is the year.

    In theory, you could use a vector instead of a map, but it’s probably going to be sparsely enough populated that a map makes more sense.

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

Sidebar

Related Questions

Possible Duplicate: substring algorithm Given two strings, A and B, how to find the
Possible Duplicate: Interview Q: given an array of numbers, return array of products of
Possible Duplicate: Getting the submatrix with maximum sum? Given a 2-dimensional array of positive
Possible Duplicate: Counting inversions in an array This is a programming question that I
Possible Duplicate: Rolling median algorithm in C Given that integers are read from a
Possible Duplicate: How to find the kth largest element in an unsorted array of
Possible Duplicate: Help with algorithm problem from SPOJ Came across this interview question. Given
Possible Duplicate: Algorithm to find Lucky Numbers I came across this question.A number is
Possible Duplicate: Algorithm to find the total number of connected sets in a matrix
Possible Duplicate: optimal algorithm for finding unique divisors I have asked this question before,

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.