easy
0 views

Meeting Late Comers In Python

Count the number of people who arrived late to a meeting that started at 10:00 AM

Understand the Problem

Problem Statement

A certain number of people attended a meeting which was to begin at 10:00 am on a given day. The arrival time in HH:MM format of those who attended the meeting is passed as the input in a single line, with each arrival time separated by a space. The program must print the count of people who came late (after 10:00 am) to the meeting.

Constraints

  • The length of the input string is between 4 to 10000 characters
  • The time format is HH:MM in 24-hour format
  • HH represents hours (00-23) and MM represents minutes (00-59)
  • Input times are valid time formats
  • At least one time will be provided

Examples

Example 1
Input
10:00 9:55 10:02 9:45 11:00
Output
2
Explanation

The 2 people were those who came at 10:02 and 11:00. The person who arrived at 10:00 is on time, and those who arrived at 9:55 and 9:45 are early.

Example 2
Input
10:01 10:00 9:59
Output
1
Explanation

Only the person who arrived at 10:01 is late. The person who arrived at 10:00 is on time, and the person at 9:59 is early.

Example 3
Input
11:30 12:45 13:15
Output
3
Explanation

All three people arrived after 10:00 AM, so all are late comers.

Solution

#include <stdio.h>
#include <string.h>

int main() {
    char input[10001];
    fgets(input, sizeof(input), stdin);
    
    int lateCount = 0;
    int hour, minute;
    char *token = strtok(input, " ");
    
    while (token != NULL) {
        // Parse the time in HH:MM format
        sscanf(token, "%d:%d", &hour, &minute);
        
        // Check if late (after 10:00)
        if (hour > 10 || (hour == 10 && minute > 0)) {
            lateCount++;
        }
        
        token = strtok(NULL, " ");
    }
    
    printf("%d\n", lateCount);
    return 0;
}
Time:O(n) where n is the number of time entries
Space:O(1) - constant extra space (excluding input storage)
Approach:

C Solution Explanation:

1. Read the entire input line into a character array
2. Use strtok() to split the string by spaces to get individual time tokens
3. For each token, use sscanf() to parse the hour and minute values from the HH:MM format
4. Apply the late arrival logic: hour > 10 OR (hour == 10 AND minute > 0)
5. Increment the counter for each late arrival
6. Print the final count

The solution uses standard C string parsing functions and handles the input efficiently with O(n) time complexity where n is the number of time entries.

Visual Explanation

Loading diagram...