Question: Principal Global | Array Pairs & String Parsing | Cracking the Principal Global Coding Round | Repeating Integers & Camera Line of Sight Latest Principal Global Placement Questions
1
Entering edit mode

Question 1: Repeating Integer Pairs

Problem Statement: You are given a list of integers. Write a program which prints all the integer pairs in the list that repeat. If the list has more than one such pair, print all the pairs in consecutive lines in a sorted order. Sorting should be performed on the first integer of the pair.

Read the input from STDIN and print the output to STDOUT. Do not write arbitrary strings while reading the input or while printing, as these contribute to the standard output and test cases will fail.

Input Format:

  • First Line has an integer, N.
  • Second Line has N integers separated by single white spaces.

Output Format:

  • The integer pairs which repeat are printed one in each line, sorted in ascending order.

Constraints:

  • 4 <= N <= 100
  • The list has at least one such integer pair.
  • The occurrences of the repetitions must always be distinct.

Sample Input 1:

  • 5
  • 1 2 3 1 2

Sample Output 1:

  • 1 2

Explanation 1: Since 1 2 is repeating in the list, it forms a couple. Hence the output is 1 2.

 


Question 2: Camera Line of Sight

Problem Statement: The input string will consist of only the characters *, #, C, and spaces. The input does not contain any leading, trailing, or consecutive spaces (other than the spaces explicitly shown between characters in the sample input).

Input Format: A single line of input containing a string that represents the layout of the control center, cameras, and obstacles. The control center is denoted by C, cameras by *, and obstacles by #. Spaces are used to represent empty spaces.

Output Format: A single line of output should consist of an integer that represents the number of cameras that can connect to the control center without any obstruction in their direct line of sight.

Sample Input 1:

  • * C * *

Sample Output 1: 3

Explanation 1: Here, three cameras can connect to the control center without any obstruction in their direct line of sight, which will be printed as output.


 

Login before adding your answer.

Similar Posts
Loading Similar Posts