Programming Problems

1. Given an array A of N integers, and a number k which is smaller than the size of the array. Write a program which returns true if the array contains duplicates within k distance.
INPUT: The first line contains the integers N and k separated by space. The second line contains the N integers separated by space.
OUTPUT: Output "Yes" if it contains duplicates within distance k else output "No".


2. Given an input string S, write a program to find the maximum occurring character in S. For example, if the input string is "tushita" then the program should return t.
INPUT: The first line contains an integer representing the size of S The second line contains the string S
OUTPUT: Maximum occurring character. If more than one character has maximum count then return the first character with the maximum count in the input string.


3. Given a number N and a digit d, find the total number of occurrence of digit d in number N
INPUT: Two numbers N and d separated by whitespace.
OUTPUT: Total number of occurrence of digit d in N


4. Given an array A of N positive integers, you are provided with two functions sumprefix(i) and sumsuffix(i).
The sumprefix(i) function computes the sum of first i numbers of the array.
The sumsuffix(i) function computes the sum of last N - i + 1 numbers of the array.
Your task is to find the minimum index i for which the value sumprefix(i) + sumsuffix(i) is the minimum. Which means you need to minimize the value of sumprefix(i) + sumsuffix(i) and find the least index i for which this value is attained.
INPUT:
The first line of input contains the integer N denoting the number of elements in array A.
The second line contains the N separated elements of array A.
OUTPUT:
Output the single line containing the answer.


5. Given an array of integers, calculate the fractions of its elements that are positive, negative, and are zeros. Print the decimal value of each fraction on a new line.
Input Format
The first line contains an integer,n , denoting the size of the array.
The second line contains n space-separated integers describing an array of numbers .
Output Format
You must print the following 3 lines:
1. A decimal representing of the fraction of positive numbers in the array compared to its size.
2. A decimal representing of the fraction of negative numbers in the array compared to its size.
3. A decimal representing of the fraction of zeros in the array compared to its size.
Sample Input
6
-4   3   -9   0   4   1
Sample Output
0.500000
0.333333
0.166667
Explanation
There are 3 positive numbers, 2 negative numbers,and 1 zero in the array.The proportions of occurrence are positive: 3/6=0.500000 , negative: 2/6=0.333333 andzeros: 1/6=0.166667.


6. Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers.
Input Format
A single line of five space-separated integers.
Output Format
Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than a 32 bit integer.)
Sample Input
1   2   3   4   5
Sample Output
10   14


7. Program to extract data from HTML tag.
Sample Input
<h1>Hello World!</h1>
Sample Output
Hello World!

No comments:

Post a Comment

Total Pageviews