Join Regular Classroom : Visit ClassroomTech

Capgemini Coding Questions Solved | On-Campus Placement | codewindow.in

Question 1:

A company wishes to encode its data. The data is in the form of a string and is case-sensitive. They wish to encode the data with respect to a specific character. They wish to count the number of times the character reoccurs in the given data so that they can encode the data accordingly. Write an algorithm to find the count of the specific character in the given data.

Input:
The first line of the input consists of a string – data representing the data to be encoded. The second line consists of a character – code representing the character to be counted in the data.

Output:
Print an integer representing the count of the specific character. If the required character is not found then print 0.

Note:
The specific character and given string consists of English letters and Special characters only.

Example:
Input:
haveagoodday
a

Output:
3

import java.util.*;
import java.lang.*;
import java.io.*;

class CodeWindow
{
	public static void main (String[] args) throws Exception
	{
		// your code goes here
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		char c = br.readLine().charAt(0);
		int count = 0;
		for(int i=0; i<str.length(); i++)
		    if(str.charAt(i) == c)
		        count++;
		System.out.println(count);
	}
}

Question 2:

A company has a sales record of N products for M days. The company wishes to know the maximum revenue a given product of the N products each day. Write an algorithm to find the highest revenue received each day.


Input:
The first line of the input consists of two space-separated Integers days and produces, representing the day products in the sales record (N), respectively, The next M lines consist of N space-separated integers – sales Record representing the grid of sales revenue or negative) received from each product each day,

Output:
Print M space-separated integers representing the maximum revenue received each day.

Example:
Input:
3 4
100 198 333 323
122 232 221 111
223 565 245 764

Output:
333 232 764

Explanation:
The maximum revenue received on the first day is 333, followed by a maximum revenue of 232 on the maximum revenue of 764 on the third day.

import java.util.*;
import java.lang.*;
import java.io.*;

class CodeWindow
{
	public static void main (String[] args) throws Exception
	{
		// your code goes here
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int m = Integer.parseInt(str[0]);
		int n = Integer.parseInt(str[1]);
		for(int i=0; i<m; i++) {
		    str = br.readLine().split(" ");
		    int max = Integer.parseInt(str[0]);
		    for(int j=1; j<n; j++)
		        if(max < Integer.parseInt(str[j]))
		            max = Integer.parseInt(str[j]);
		    System.out.print(max + " ");
		}
	}
}
Recent Posts