IBM CIC off campus coding assessment questions and answers

0
216
IBM CIC off campus coding assessment questions and answers
IBM CIC off campus coding assessment questions and answers
Telegram Group Join Now
Instagram Page Join Now
whatsApp Channel Join Now
5/5 - (1 vote)

IBM CIC Off Campus Coding Assessment Questions and Answers (2025): If you are preparing for the IBM CIC Off Campus Hiring 2025 or associate system engineer role, one of the key rounds is the online coding assessment. This round tests your problem-solving skills, logical thinking, and clean coding practices.

In this blog, we will discuss a realistic coding question that has been asked in IBM off campus assessments. Along with the question, explanation, and sample solution, this post will help you understand how to approach such problems during the test.

First Coding Question: Top K Frequent Words

Problem Statement:
You are given an array of strings words and an integer k. Return the k most frequent words sorted by:

  1. Frequency (highest first)
  2. If two words have the same frequency, sort them in lexicographical (alphabetical) order.

Example 1

Input:

words = ["i","love","leetcode","i","love","coding"], k = 2

Output:

["i","love"]

Explanation:

  • Frequency → “i”: 2, “love”: 2, “leetcode”: 1, “coding”: 1
  • Top 2 are “i” and “love”
  • Since both have same frequency, sorted alphabetically → “i” comes before “love”.

Example 2

Input:

words = ["the","day","is","sunny","the","the","the","sunny","is","is"], k = 4

Output:

["the","is","sunny","day"]

Explanation:

  • Frequencies → the:4, is:3, sunny:2, day:1
  • Top 4 are the, is, sunny, day (in this order)

Constraints

  • 1 ≤ words.length ≤ 500
  • 1 ≤ words[i].length ≤ 10
  • words[i] consists of lowercase English letters
  • k is between 1 and number of unique words

Approach to Solve the Problem

  1. Count the frequency of each word using a hash map or dictionary.
  2. Sort the words based on two keys:
    • Higher frequency first
    • If frequencies are same, by alphabetical order
  3. Return the first k words from the sorted list.

Sample Python Solution

from collections import Counter

def topKFrequent(words, k):
    # Step 1: Count frequency of each word
    count = Counter(words)
    
    # Step 2: Sort words by (-frequency, word)
    sorted_words = sorted(count.keys(), key=lambda x: (-count[x], x))
    
    # Step 3: Return top k
    return sorted_words[:k]

# Example usage
print(topKFrequent(["i","love","leetcode","i","love","coding"], 2))
# Output: ['i', 'love']

print(topKFrequent(["the","day","is","sunny","the","the","the","sunny","is","is"], 4))
# Output: ['the', 'is', 'sunny', 'day']

Second Coding Question: IBM CIC off campus coding assessment questions and answers

Top K Frequent Words : Given an integer n, return a string array answer (1-indexed) where:

  • answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
  • answer[i] == "Fizz" if i is divisible by 3.
  • answer[i] == "Buzz" if i is divisible by 5.
  • answer[i] == i (as a string) if none of the above conditions are true.

Example 1:

Input: n = 3
Output: ["1","2","Fizz"]

Example 2:

Input: n = 5
Output: ["1","2","Fizz","4","Buzz"]

Example 3:

Input: n = 15
Output: ["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]

Constraints:

  • 1 <= n <= 104

✅ Python Solution

def fizzBuzz(n):
    result = []
    for i in range(1, n + 1):
        if i % 3 == 0 and i % 5 == 0:
            result.append("FizzBuzz")
        elif i % 3 == 0:
            result.append("Fizz")
        elif i % 5 == 0:
            result.append("Buzz")
        else:
            result.append(str(i))
    return result

# Example Usage
print(fizzBuzz(3))   # ['1','2','Fizz']
print(fizzBuzz(5))   # ['1','2','Fizz','4','Buzz']
print(fizzBuzz(15))  # ['1','2','Fizz','4','Buzz','Fizz','7','8','Fizz','Buzz','11','Fizz','13','14','FizzBuzz']

Tips for IBM CIC Coding Assessment

  • Write clean and well-commented code
  • Always check edge cases (like ties in frequency, or only one word present)
  • Focus on time complexity—IBM tests your logic efficiency too
  • Practice similar string manipulation and sorting problems before the test

Check Out Other IBM Coding Questions 2025

  1. IBM Software Developer coding questions: Click Here
  2. IBM Test question & Answer: Click Here

LEAVE A REPLY

Please enter your comment!
Please enter your name here