Академический Документы
Профессиональный Документы
Культура Документы
Question - 1
Buying Show Tickets
Input Format
Locked stub code in the editor reads the following input from
stdin and passes it to the function:
The first line contains an integer, n, denoting the number of
elements in tickets .
Each line i of the n subsequent lines contains an integer
describing tickets i.
The last line contains an integer, p.
Constraints
5
1 n 105
1 tickets[i] 109, where 0 i < n.
0p<n
Output Format
Return an integer denoting the number of seconds it takes for
Jesse to finish purchasing exactly tickets p tickets.
Sample Input 0
5
2
6
3
4
5
2
Sample Output 0
12
Explanation 0
Given tickets = [2, 6, 3, 4, 5], Jesse's wait time looks like this:
0. window 2 6 3 4 5
1. window 6 3 4 5 1
2. window 3 4 5 1 5
3. window 4 5 1 5 2
4. window 5 1 5 2 3
5. window 1 5 2 3 4
6. window 5 2 3 4 (the person at the head of the line
in the previous step purchased their last ticket and does not
re-enter the line)
7. window 2 3 4 4
8. window 3 4 4 1
9. window 4 4 1 2
10. window 4 1 2 3
11. window 1 2 3 3
12. window 2 3 3 (Jesse purchased his last ticket and
does not re-enter the line)
Because it took a total of twelve seconds for Jesse to purchase
all tickets 2 = 3 tickets, we return 12.
Sample Input 1
4
1
1
1
1
0
Sample Output 1
Explanation 1
Given tickets = [1, 1, 1, 1], Jesse's wait time looks like this:
0. window 1 1 1 1
1. window 1 1 1 (Jesse purchased his ticket and does not
re-enter the line)
Because it took a total of one second for Jesse to purchase
tickets 0 = 1 ticket, we return 1.
Sample Input 2
4
5
5
2
3
3
Sample Output 2
11
Given tickets = [5, 5, 2, 3], Jesse's wait time looks like this:
0. window 5 5 2 3
1. window 5 2 3 4
2. window 2 3 4 4
3. window 3 4 4 1
4. window 4 4 1 2
5. window 4 1 2 3
6. window 1 2 3 3
7. window 2 3 3 (the person at the head of the line in
the previous step purchased their last ticket and does not
re-enter the line)
8. window 3 3 1
9. window 3 1 2
10. window 1 2 2
11. window 2 2 (Jesse purchased his last ticket and does not
re-enter the line)
Because it took a total of eleven second for Jesse to purchase all
tickets 3 = 3 tickets, we return 11.
Question - 2
Animal Inheritance
Input Format
There is no input for this challenge.
Output Format
The getGreeting() method must always return a string denoting
the appropriate greeting for the implementing class.
Sample Output
Question - 3
import java.util.*;
List<String> doStuff(List<String> z) {
z.add("9");
return z;
}
}
interface Pancake {
List<String> doStuff(List<String> s);
}
[3, 7,
5]
[3, 7, 5,
9]
[3, 7, 5, 9,
1]
Compilation fails.
An exception is thrown at
runtime.
Question - 4
1,2
5,2
1,6
5,6
Question - 5
1. public class A {
2. int add(int i, int j){
3. return i+j;
4. }
5. }
6. public class B extends A{
7. public static void main(String argv[]){
8. short s = 9;
9. System.out.println(add(s,6));
10. }
11.}
15
Question - 6
Question - 7
87
10 7