Problem
As per COVID-19 rules, your college is taking online classes. Your professor takes class from StartTime(hh:mm:ss) to EndTime(hh:mm:ss). He uses a chrome extension to track when a student joins the class and leaves the class with their Student ID(SID). He stores it in a student tracker file and then circulates it in your college group. Now, your teacher is very strict. He wants to take attendance at a moment when the number of students present in the class is minimum. If there are multiple such times he can choose a time with equal probability and will take the attendance. Now, you know your teacher's algorithm and you have access to the student tracker file.
Task
Print 0 if the probability that you (SID=1) will get the attendance is zero otherwise print the probability in P/Q format where GCD(P, Q)=1, where GCD(P, Q) denotes the greatest common divisor of integers P and Q.
Note: Each student can join the class at multiple intervals. Like they can join at "12:00:00" then leave at "12:15:00", then again join at "12:35:00", and leave at "12:50:00".
Example
Assumptions
- N = 2
- StartTime = "12:00:00"
- EndTime = "12:45:00"
- The next N lines are:
- SID1 = 2, M1 = 2, Time1 = [[12:00:00, 12:15:00] [12:20:00, 12:45:00]]
- SID2 = 1, M2 = 1, Time2 = [[12:00:00, 12:44:00]]
Approach
- The minimum number of students is 1 and is at any second from "12:15:00" to "12:19:59" or at any second from "12:44:00" to "12:44:59".
- During these times you are available from "12:15:00" to "12:19:59".
- So the probability that you(SID=1) will get the attendance is 5/6.
Input format
Note: This is the input format you must use to provide custom input (available above the Compile and Test button).
- The first line contains N denoting the number of students.
- The second line contains two space-separated strings StartTime and EndTime of class in hh:mm: ss format("00:00:00" to "23:59:59")
- The next N lines have Student ID(SID), the number of intervals the student joined the class(M), and M pairs of [ArrivalTime, LeaveTime] in hh:mm:ss format for each M interval.
Output format
Print 0 if the probability that you (SID=1) will get the attendance is zero otherwise print the probability in P/Q format where GCD(P, Q)=1, where GCD(P, Q) denotes the greatest common divisor of integers P and Q.
Constraints
3 12:00:00 13:00:00 2 2 12:00:00 12:25:00 12:56:00 13:00:00 1 1 12:00:00 12:56:00 3 1 12:00:00 13:00:00
Example
Given
- N = 3
- StartTime = "12:00:00"
- EndTime = "13:00:00"
- Next N lines are:
- SID1 = 2, M1 = 2, Time1 = [[12:00:00, 12:25:00] [12:56:00, 13:00:00]]
- SID2 = 1, M2 = 1, Time2 = [[12:00:00, 12:56:00]]
- SID2 = 3, M2 = 1, Time2 = [[12:00:00, 13:00:00]]
Approach
- The minimum number of students is 2 and is at any second from "12:25:00" to "12:59:59".
- During these times you are available from "12:25:00" to "12:55:59".
- So the probability that you(SID=1) will get the attendance is 31/35.
Code(JAVA):-
Recommended Post :-
- Swap the adjacent characters of the string
- Double the vowel characters in the string
- Character with their frequency
- Program to find the closest value
- Swap adjacent characters
- Double the vowel characters
- Check valid parenthesis
- Print the characters with their frequencies
- Find closest value
- Word Count
- Program of CaesarCipher
- Program to find the perfect city
- Annual Day | Tech Mahindra coding question
- Find the number of pairs in the array whose sum is equal to a given target.
Full C course:-
Key points:-
- How to set limit in the floating value in python
- What is boolean data type
- How to print any character without using format specifier
- How to check that given number is power of 2 or not
- How to fix limit in double and floating numbers after dot (.) in c++
- How to print a double or floating point number in scientific notation and fixed notation
- How to take input a string in c
- How to reduce the execution time of program in c++.
Cracking the coding interview:-
Array and string:-
Tree and graph:-
Hackerearth Problems:-
- Very Cool numbers | Hacker earth solution
- Vowel Recognition | Hackerearth practice problem solution
- Birthday party | Hacker earth solution
- Most frequent | hacker earth problem solution
- program to find symetric difference of two sets
- cost of balloons | Hacker earth problem solution
- Chacha o chacha | hacker earth problem solution
- jadu and dna | hacker earth solution
- Bricks game | hacker earth problem
- Anti-Palindrome strings | hacker earth solution
- connected components in the graph | hacker earth data structure
- odd one out || hacker earth problem solution
- Minimum addition | Hackerearth Practice problem
- The magical mountain | Hackerearth Practice problem
- The first overtake | Hackerearth Practice problem
- Playing With Characters | Hackerrank practice problem solution
- Sum and Difference of Two Numbers | hackerrank practice problem solution
- Functions in C | hackerrank practice problem solution
- Pointers in C | hackerrank practice problem solution
- Conditional Statements in C | Hackerrank practice problem solution
- For Loop in C | hackerrank practice problem solution
- Sum of Digits of a Five Digit Number | hackerrank practice problem solution
- 1D Arrays in C | hackerrank practice problem solution
- Array Reversal | hackerrank practice problem solution
- Printing Tokens | hackerrank practice problem solution
- Digit Frequency | hackerrank practice problem solution
- Calculate the Nth term | hackerrank practice problem solution
Data structure:-
- Program to find cycle in the graph
- Implementation of singly link list
- Implementation of queue by using link list
- Algorithm of quick sort
- stack by using link list
- program to find preorder post order and inorder of the binary search tree
- Minimum weight of spanning tree
- Preorder, inorder and post order traversal of the tree
MCQs:-
0 Comments