Sei sulla pagina 1di 4

1) Task 1: Socks Merchant

Description :
John works at a clothing store. He has a large pile of socks that he must pair by color for sale.
Given an array of integers representing the color of each sock, determine how many pairs of socks
with matching colors there are.
For example, there are n = 7 socks with colors ar = [1,2,1,2,1,3,2]. There is one pair of color 1 and
one of color 2. There are three odd socks left, one of each color. The number of pairs is 2.
Input Format
The first line contains an integer n, the number of socks represented in Array ar.
The second line contains n space-separated integers describing the colors of the socks in the pile.
Output Format
Return the total number of matching pairs of socks that John can sell.

Sample Input
9
10 20 20 10 10 30 50 10 20

Sample Output
3
2) Task 2: Alternating Characters
Description :
You are given a string containing characters ‘A’ and ‘B’ only. Your task is to change it into a string
such that there are no matching adjacent characters. To do this, you are allowed to delete zero or
more characters in the string.
Your task is to find the minimum number of required deletions.
For example, given the string s = AABAAB , remove an A at positions 0 and 3 to make s = ABAB in
2 deletions.
Input Format
The first line contains an integer q , the number of queries.
The next q lines each contain a string s.
Output Format
For each query, print the minimum number of deletions required on a new line.

Sample Input
5
AAAA
BBBBB
ABABABAB
BABABA
AAABBB
Sample Output
3
4
0
0
4
3) Task 3 :
Description:
You have to write a method named “getMinMax(int[] myArray)” which accepts an integer array
as one paramter. This method must be overloaded with another version which accepts 1 more
parameter as intege. Both overloaded version should return an Object of a custom Class. Let’s
call the custom class ArrayDimension.
This Class ArrayDimension should have 2 members
i) minValue
ii) maxValue.
The Above method should return an object of this class ArrayDimension, in which the minValue
should have the value of the least number provided in the Array as argument & the maxValue
should have the highest value in the Array.
The overloaded version, should have the same characteristics as above, but the additional
integer parameter, decided which minimum or which maximum should be returned.

e.g.
Input -> getMinMax( { 4,78, 55, 99, 32, 46, 75, 0} )
this should give an output of min:0 & max:99
Input -> getMinMax( { 4,78, 55, 99, 32, 46, 75, 0}, 2)
this should give an output of min:4 & max:78

4) Task 4:
Description :
Write a method addBusinessDays which accepts 1 integer argument daysToAdd & 1 date
argument startDate. The method should return a date after adding the daysToAdd to the
startDate, but it should skip weekends.
e.g.
Input -> addBusinessDays(4, 28-Jan-19)
this should give an output of 1-Feb-19
Input -> addBusinessDays(5, 28-Jan-19)
this should give an output of 4-Feb-19
(because the 5th day falls on Saturday, so it will be skipped. Again the next day is Sunday, so
again it will be skipped. Hence the 5th day should fall on Monday i.e. 4-Feb-19)
Input -> addBusinessDays(15, 28-Jan-19)
this should give an output of 18-Feb-19
5) Task 5:
Description : There is a list of names in a text file. There is a 2nd list of names in an Excel File. The list
might not be the same. You have to write a code, that will check the following.
1) If the name is present in Excel & the text file, then in the Excel file, in the adjacent column you will
write “verified”
2) If the name is present in Excel but the name is not present in the Text File, you will write “new”
3) If the name is present in Text File, but the name is not present in Excel, you will write “missing”.

Potrebbero piacerti anche