Below we are providing Q & A for 28th Sep 2021 11 AM slot.
Question 1:
A man invests a certain amount on monthly basis in a bank. He withdraws that money once in 4 years which is a leap year, to make a big scale purchase .He starts next investment exactly 183 days after the purchase .
Initially, he makes a note of his purchase date
Given the date(dd) and month(mm) of his purchase. The task here is to help him find the date and month to start his investment.
His next investment date is calculated from the next day of his purchase.
Display the date as on 183rd day.
This question was asked in 28th September 2021 Morning Slot at 11 am
Solution: (Java)
import java.util.Scanner; class Srk { public static void getDate(int d, String m) { int[] days = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; String[] month = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; int count = 183; int current_month = 0; for(int i = 0; i < 12; i++) if (m == month[i]) current_month = i; int current_date = d; while (true) { while (count > 0 && current_date <= days[current_month]) { count -= 1; current_date += 1; } if (count == 0) break; current_month = (current_month + 1) % 12; current_date = 1; } System.out.println(current_date + " " +month[current_month]); } public static void main(String args[]) { int D; String M; Scanner sc=new Scanner(System.in); D=sc.nextInt(); M=sc.next(); getDate(D, M); } }
Question 2:
There are ‘N’ number of companies participating in the drive. The commencement timings of the interviews of ‘N’ companies is given as start[] array elements and their respective end timings are given as end[] array elements. The task here is to find the maximum number of interviews a single candidate can attend keeping the following points in mind:
All the interview timings are in ‘p.m’.
• The candidate cannot attend an interview if its timings overlap with the timings of another company’s interview. Say, an interview starts at 1 p.m. and ends at 4 p.m., he cannot attend the interview of another company between 1 p.m. to 4 p.m.
Only one candidate can be scheduled in the given time slot
Assume, the input for end time(end[]) is always sorted in ascending order.
Solution : (Java)
import java.util.Scanner;
class Srk
{
public static void main(String args[])
{
Scanner Sc=new Scanner(System.in);
int size=Sc.nextInt();
int[] starttime=new int[size];
int[] endtime=new int[size];
for(int i=0;i<size;i++)
{
starttime[i]=Sc.nextInt();
}
for(int j=0;j<size;j++)
{
endtime[j]=Sc.nextInt();
}
int count=1;
int result=endtime[0];
for(int k=0;k<size-1;k++)
{
if(result<=starttime[k+1])
{
result=endtime[k+1];
count++;
}
}
System.out.println(count);
}
}
0 Comments