Post

IBM Mock Coding Interview

IBM mock coding Hackerrank OA

IBM Mock Coding Interview

Q1: Count the Employees

The data for the number employed at several famous IT companies is maintained in the COMPANY table. Write a query to print the IDs of the companies that have more than 10,000 employees, in ascending order of ID.

Input Format:

NameTypeDescription
IDIntegerA company ID in the inclusive range [1,1000]. This is the primary key.
NAMEStringA company name. This field contains between 1 and 100 characters (inclusive).
EMPLOYEESIntegerThe total number of employees in the company.

Output Format:
The result should contain the IDs of all the companies that have more than 10,000 employees, in ascending order in the following format:

1
COMPANY.ID

Sample Input:

IDNAMEEMPLOYEES
1Adobe28085
2Flipkart35543
3Amazon1089
4Paytm9982
5BookMyShow5589
6Oracle4003
7NIIT57782
8Samsung2000
9TCS10046
10Wipro3500

Sample Output:

1
2
3
4
1
2
7
9

Explanation:
Adobe, Flipkart, NIIT, and TCS have greater than 10,000 employees, so their IDs are printed.

Q1 Solution:

1
2
3
4
SELECT ID
FROM COMPANY
WHERE EMPLOYEES > 10000
ORDER BY ID;

Q2: FizzBuzz

Given a number n, for each integer i in the range from 1 to n inclusive, print one value per line as follows:

  • If i is a multiple of both 3 and 5, print FizzBuzz.
  • If i is a multiple of 3 (but not 5), print Fizz.
  • If i is a multiple of 5 (but not 3), print Buzz.
  • If i is not a multiple of 3 or 5, print the value of i.

Function Description:
Complete the function fizzBuzz in the editor below. fizzBuzz has the following parameter(s):

  • int n: upper limit of values to test (inclusive)

Returns: NONE
Prints: The function must print the appropriate response for each value i in the set {1, 2, ... n} in ascending order, each on a separate line.

Constraints:
\(0 < n < 2 \times 10^5\)

Input Format for Custom Testing:
Input from stdin will be processed as follows and passed to the function.
The single integer n, the limit of the range to test: [1, 2, ... n].

Sample Case 0
Sample Input:

1
2
3
STDIN   Function
-----   --------
15  ->  n = 15

Sample Output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

Explanation:

  • The numbers 3, 6, 9, and 12 are multiples of 3 (but not 5), so print Fizz on those lines.
  • The numbers 5 and 10 are multiples of 5 (but not 3), so print Buzz on those lines.
  • The number 15 is a multiple of both 3 and 5, so print FizzBuzz on that line.
  • None of the other values is a multiple of either 3 or 5, so print the value of i on those lines.

Q2 Solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Complete the 'fizzBuzz' function below.
# The function accepts INTEGER n as parameter.
def fizzBuzz(n):
    # Write your code here
    for i in range(1, n + 1):
        if i % 3 == 0 and i % 5 == 0:
            print("FizzBuzz")
        elif i % 3 == 0:
            print("Fizz")
        elif i % 5 == 0:
            print("Buzz")
        else:
            print(i)

if __name__ == '__main__':
    n = int(input().strip())

    fizzBuzz(n)
This post is licensed under CC BY 4.0 by the author.