Traverse a singly linked list from the beginning to the end and reverse all the increasing and decreasing sequence of components present in the list. Component is the collection of continuous elements either in increasing or decreasing order. Example: Let the list contains 1, 2, 3, 7, 4, 2, 9, 7, 8 elements. Here the components are “1, 2, 3, 7”, “4, 2”, “9, 7”, and “8”. The code should produce the list with elements 7, 3, 2, 1, 2, 4, 7, 9, 8.
For each of the following, write a single statement that performs the single task. Define two integer
variables val1 and val2. Initialize the val1 to 2300.
1. Define a pointer myPointer to an object of type integer.
2. Assign the address of variable val1 to pointer.
3. Print the value of the object pointed to by myPointer.
4. Assign the value of the object pointed to by myPointer to variable val2.
5. Print the value of val2.
6. Print the address of val1.
7. Print the address stored in myPointer
Number of digits until N
Given an integer N, write a program that prints the count of the total number of digits between 1 and N.
Input
The input is a positive integer.
The output should be a single line containing the count of the digits up to the given number.
Given
N = 10From 1 to 9, each number contains a single digit. From 10 onwards, the numbers contain two digits.
So the output should be 9 + 2 =
11.
Sample Input 1
10
Sample Output 1
11
Sample Input 2
4
Sample Output 2
4
Product of Numbers from M to N
Given two integers M, N. Write a program to print the product of numbers in the range M and N (inclusive of M and N).
Input
The first line of input is an integer M. The second line of input is an integer N.
Explanation
In the given example, the product of numbers between the range
2 and 5 is 2 * 3 * 4 * 5. Therefore, the output should be 120.
Sample Input 1
2
5
Sample Output 1
120
Sample Input 2
1
4
Sample Output 2
24
Sum of K powers
Write a program to print the sum of the Kth power of the first N natural numbers.
Input
The first line of input is an integer N. The second line of input is an integer K.
Explanation
In the given example, the sum of first
5 natural numbers power of 3.The sum should be 13 + 23 + 33 + 43 + 53
Therefore, the output should be
225.
Sample Input 1
5
3
Sample Output 1
225
Sample Input 2
2
8
Sample Output 2
257
Product of the Given Numbers
Given an integer N, write a program which reads N inputs and prints the product of the given input integers.
Input
The first line of input is a positive integer, N. The next N lines each contain an integer.
Output
The output should be the product of the given input integers.
In the given example,
N = 3 and the input integers are 2, 3, and 7.So, the output should be 2 x 3 x 7 = 42.
Sample Input 1
3
2
3
7
Sample Output 1
42
Sample Input 2
4
11
2
4
9
Sample Output 2
792
Denominations - 4
Write a program to find the minimum number of notes required for the amount M. Available note denominations are 2000, 500, 200, 50, 20, 5, 2, 1.
Input
The first line is a single integer M.
Output
Print M in denominations.
Explanation
Given
M = 2257 Then 2257 can be written as
2000 * 1 + 500 * 0 + 200 * 1 + 50 * 1 + 20 * 0 + 5 * 1 + 2 * 1 + 1 * 0So the output should be
2000:1 500:0 200:1 50:1 20:0 5:1 2:1 1:0.
Sample Input 1
2257
Sample Output 1
2000:1 500:0 200:1 50:1 20:0 5:1 2:1 1:0
Sample Input 2
2345
Sample Output 2
2000:1 500:0 200:1 50:2 20:2 5:1 2:0 1:0
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.
Devise an algorithm to find him the shuttle with the least waiting time. (waiting time = boardingj - t , where j is the next shuttle. And boardingj >= t ) for each ti
If he also has access to the travel time of each shuttle. Can you help him find the shuttle which will help him reach his destination at the earliest ?
Return an array of shuttle indexes that Rahul took for n days.