Write a program using an overloaded function(s) named convert() that work as given below:
i. public void convert(int seconds)
This function converts and displays number of seconds to hour, minutes and seconds
ii. public void convert(double days)
This function converts and displays number of days to years, months and days
Call the above functions from main.
Assume that the coin information is given to you in the form of an ‘n’ element array A. A[i] is a number between 1 and n and A[i] = j means that the j’th smallest pancake is in position i from the top; in other words A[1] is the size of the top most coin (relative to the others) and
A[n] is the size of the bottommost coin.
operation(A, n) should be assumed to be O(1) can be used directly in pseudo code, it flips first n coins.
Consider a pile of coins. You have given ‘n’ coins of different sizes and you want to sort the pile so that smaller coins are on the top of larger ones. The only “operation” you are allowed to perform is- take top ‘k’ coins together, and place them back to the pile upside down
Rahul lives in City A and would like to travel to City B for work. There is a shuttle service for people in these cities which has a fixed schedule. The schedule for City A is a list of boarding times(at City A) and departure times(from City A) for each bus.
Note: No one is allowed to board a shuttle after the boarding time.
He arrives at time t and sometimes has to wait at the station. You are given a list of arrival times for n days.
Mickeymouse loves numbers in the range [m1, m2] (m1 and m2 included). Minnie decides to gift Mickey an array of numbers for his birthday. Mickey wants to find the number of pairs of indices [l, r] for which the sum of all the elements in the range [l, r] lies between m1 and m2.
Sample case:
Array = [-2, 5, -1]
M1 = -2
M2 = 2
Output: 3
[[0, 0], [2, 2], [0, 2]] are the three pairs of [l, r] that satisfy the condition. So, that is why, the output is 3.
Notes: Recurrence relation not needed in first two parts. But do explain the reason for the resulting time complexity in words.
Akshita loves chocolates, numbers and algorithms. Her friends Ina and Mina gave her a and b chocolates respectively. Given her love for numbers, she likes all the numbers that are divisible by either ‘a’ or ‘b’ or both. She wants to find the nth smallest such number that is divisible by either a or b. Suggest her an algorithm to find the desired number, describe the principle on which the algorithm is based, write the pseudocode and the recurrence relation for the same. Also state which subproblem will give the answer to the original problem.
Expected Complexity → O(log(N∗min(A,B))).
Assume a and b to be co-prime positive integers.
12. Write a Java program to print the sum of two numbers.
13. Write a Java program that simulates a guessing number game. The program will generate a random value the user needs to guess and keep asking the user for a guess until the user provides the expected value. If a value has already provided, the program will print the message “Value already provided”. If the value is higher than the value to guess, the program will print“Too high”; if it is less, the program will print the message “Too low”. Once the user enters the expected value, the program will print the number of attempts.
12. Show the Java code to declare and allocate an array with 497 elements of type double.
13. Print i as long as i is less than 6.
11.Evaluate the following Java expressions, assuming x and y are both declared as integer variables and x = 17and y = 6:
x/y+3 =
x%y*4 =
x-y/3 =