0% found this document useful (0 votes)
1 views6 pages

Coding Questions

The document contains a series of programming tasks and examples, including merging sorted arrays, generating patterns, removing duplicates from arrays, finding pairs with a specific sum, and calculating bus fares based on distances. It also includes tasks related to identifying missing coins, printing specific words from sentences, and checking for palindromes in arrays. Each task is presented with examples to illustrate the expected output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views6 pages

Coding Questions

The document contains a series of programming tasks and examples, including merging sorted arrays, generating patterns, removing duplicates from arrays, finding pairs with a specific sum, and calculating bus fares based on distances. It also includes tasks related to identifying missing coins, printing specific words from sentences, and checking for palindromes in arrays. Each task is presented with examples to illustrate the expected output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Given two sorted array, merge them in a way that the third array is also sorted
(don’t use any sorting techniques)
Example
A: [5,10,27,58]
B: [2,4,9,45,67,70,89,92]
C: [2,4,5,9,10,27,45,58,67,70,89,92]

2.
1

121

12321

1234321

123454321

======================================================
==

3. Write a function to remove the duplicates from array


Example
Array: [1,3,4,1,2,3,4,1]
Output: [1,3,4,2]

4. 1
26

3 7 10

4 8 11 13

5 9 12 14 15

==================================================================
==
5. Write a function to find all the pairs from array whose sum is a given number
Where the array and number k is passed to function

Example
Array: 4, -5, 9, 11, 25, 13, 12, 8
Number: 20
Pairs of elements whose sum is 20 are:
-5 + 25 = 20
8 + 12 = 20
9 + 11 = 20

6.
* *

* *

* *

* *

* *

* *

==============================================================
==

7. Given an array which contains the combination of zeros & non zero elements
Write a function to shift the elements in a such a way that all zeros before the non zero
elements
Example:
Array: [1,5,0,9,34,23,0,10,0,22]
Output: [0,0,0,1,5,9,34,23,10,22]

8.
1
212
32123
4321234
32123
212
1
9. A City Bus is a Ring Route Bus which runs in circular [Link] is, Bus once
starts at the Source Bus Stop, halts at each Bus Stop in its Route and at the
end it reaches the Source Bus Stop again.

If there are n number of Stops and if the bus starts at Bus Stop 1, then after
nth Bus Stop, the next stop in the Route will be Bus Stop number 1 always.
If there are n stops, there will be n [Link] path connects two stops.
Distances (in meters) for all paths in Ring Route is given in array Path[]
as given below:

Path = [800, 600, 750, 900, 1400, 1200, 1100, 1500]

Fare is determined based on the distance covered from source to destination


stop as Distance between Input Source and Destination Stops can be measured
by looking at values in array Path[] and fare can be calculated as per following
criteria:

If d =1000 metres, then fare=5 INR


(When calculating fare for others, the calculated fare containing any fraction
value should be ceiled. For example, for distance 900n when fare initially
calculated is 4.5 which must be ceiled to 5)
Path is circular in function. Value at each index indicates distance till
current stop from the previous one. And each index position can be mapped with
values at same index in BusStops [] array, which is a string array holding
abbreviation of names for all stops as-
“Fergusson College “ = “FC” , “Shivaji Nagar” = “SN”, “Pune Station” = “PN”, “Swagate” =
“SW” , “Kothrud Depot” = “KD”“Magarpatta” = “MG” ,“Katraj” =”KT”

Given, n=8, where n is number of total BusStops.


BusStops = [ “FC”, ”SN”, ”PN”, ”SW”, ”KD”, ”MG”, ”KT”,”FC” ]

Write a code with function getFare(String Source, String Destination) which


take Input as source and destination stops(in the format containing first two
characters of the Name of the Bus Stop) and calculate and return travel fare.

Example 1:
Input Values:KD KT

Output Values :

10.
10101
01010
10101
01010
10101
11. A teacher came to class with a large box tokhat has several coins. Each coin has a number
printed on it. Before coming to class, she ensured that All the numbers occur an Even number
of times. However, while coming to the class, one coin fell down and got lost. She wants to
find out the number on the missing coin.
Inputs: The original number of coins and the actual number on each of the coins, seperated by
spaces.
Output: The number on the missing coin
Sample Input: 8
5727525
Sample Output: 5

12.
********1********
*******2*2*******
******3*3*3******
*****4*4*4*4*****
****5*5*5*5*5****

13. Write a program to print words starting with ‘s’ in given sentence
Example
Sentence: 'Print only the words that start with s in this sentence'
Output:
Start
S
Sentence

14.
*
*
*
*
*

15. Print 1 to 100 in snakes and ladder using array


16.
12345
23451
34512
45123
5 1234

17. Accept an array from user with 10 numbers sort the numbers in ascending order.
Now, find out the two consecutive numbers having maximum difference
Eg.
[ 8, 10 , 0 , 1 , 37 , 79 , 88 , 17 , 1 , 28 ]
Sorted Array will be
[ 0, 1, 1, 8 , 10 , 17, 28, 37, 79, 88]
the two consecutive numbers having maximum difference
37, 79 difference is 42

18.

*
***
*****
*******
*********
*******
*****
***
*
19. Write a Java method to check if an array of integers is a palindrome. An array is a palindrome
if it reads the same forwards and backwards.

20.
* * * * * *
* *
* *
* *
* *
* * * * * *

You might also like