Nokia interview questions & answers

11 real Nokia interview questions with full model answers — Coding. Drawn from the same verified bank ChannelPulse drills from (11 Nokia questions in total).

CodingEasyNokiaSoftware Engineer

1. Valid Parentheses (LeetCode)

Model answer

The task

Determine whether a string of opening and closing round, square, and curly brackets is correctly nested and matched. Return a boolean.

Key idea

A closing bracket must match the most recent unmatched opening bracket. A stack captures that order: push openings, and check each closing bracket against the stack’s top.

Approach

  1. Return False if the string has odd length.
  2. Map each closing bracket to its matching opening bracket.
  3. Scan the string from left to right.
  4. Push opening brackets onto the stack.
  5. For a closing bracket, return False if the stack is empty or its top does not match; otherwise pop.
  6. Return True only if the stack is empty after the scan.
class Solution:
    def isValid(self, s: str) -> bool:
        pairs = {")": "(", "]": "[", "}": "{"}
        openings = set(pairs.values())
        stack = []

        for char in s:
            if char in openings:
                stack.append(char)
            else:
                # A closing bracket must match the latest unmatched opening.
                if not stack or stack[-1] != pairs.get(char):
                    return False
                stack.pop()

        # Unmatched opening brackets make the sequence invalid.
        return not stack

Complexity:

  • Time: O(n), where n is the string length; each character is processed once.
  • Space: O(n) in the worst case, when all characters are opening brackets.

Common follow-ups

  • How would you support additional bracket types? Add their matching pairs to the map.
  • Can you stop early? Yes; return False as soon as a closing bracket mismatches or has no opening bracket.
  • What if the input includes non-bracket characters? Define how to handle them, then either ignore them or reject them during the scan.
CodingEasyNokiaSoftware Engineer

2. Fizz Buzz (LeetCode)

Model answer

The task

For each integer from 1 through n, produce a string: use "Fizz" for multiples of 3, "Buzz" for multiples of 5, and "FizzBuzz" for multiples of both. Otherwise, use the number’s decimal representation.

Key idea

Check divisibility by both numbers before checking either one separately. Build the result in order with a single pass.

Approach

  1. Create an empty list for the output strings.
  2. Visit each integer from 1 through n.
  3. If it is divisible by both 3 and 5, append "FizzBuzz".
  4. Otherwise, append the matching single word, or the number as a string.
  5. Return the list.
from typing import List

class Solution:
    def fizzBuzz(self, n: int) -> List[str]:
        result = []

        for number in range(1, n + 1):
            if number % 15 == 0:
                result.append("FizzBuzz")
            elif number % 3 == 0:
                result.append("Fizz")
            elif number % 5 == 0:
                result.append("Buzz")
            else:
                result.append(str(number))

        return result

Complexity:

  • Time: O(n), since each number is processed once.
  • Space: O(n), for the returned list of strings.

Common follow-ups

  • How would you support a different set of divisors and words? Iterate over divisor-word pairs and combine the words for every divisor that divides the current number.
  • How could you avoid checking divisibility with modulo? Maintain counters for each divisor and reset them when they reach that divisor.
  • What if the output is too large to keep in memory? Yield each string as it is produced, or write it directly to a stream.
CodingEasyNokiaSoftware Engineer

3. Longest Common Prefix (LeetCode)

Model answer

The task

Given a list of strings, return the longest string that is a prefix of every entry. If there is no shared prefix, return an empty string.

Key idea

Compare characters at the same position across all strings, starting from the first string. Stop at the first mismatch or when any string runs out.

Approach

  1. If the list is empty, return an empty string.
  2. Scan each character of the first string from left to right.
  3. For each position, compare that character with the character at the same position in every other string.
  4. If a string is too short or a character differs, return the matching prefix before that position.
  5. If all positions match, return the first string.
from typing import List

class Solution:
    def longestCommonPrefix(self, strs: List[str]) -> str:
        if not strs:
            return ""

        first = strs[0]

        for i, char in enumerate(first):
            for word in strs[1:]:
                if i == len(word) or word[i] != char:
                    return first[:i]

        return first

Complexity:

  • Time: O(S), where S is the total number of characters inspected.
  • Space: O(1) auxiliary space, excluding the returned prefix.

Common follow-ups

  • How would you handle many prefix queries over the same set of strings? Build a trie once, then traverse it to find shared prefixes.
  • Could sorting help? Yes. Sort the strings and compare only the first and last; their common prefix is shared by all strings.
  • What if strings arrive as a stream? Keep a running prefix and shorten it as each new string arrives.
CodingEasyNokiaSoftware Engineer

4. Reverse Linked List (LeetCode)

Model answer

The task

Given the head of a singly linked list, reverse its links in place and return the new head.

Key idea

Recursively reverse the list starting at the second node. As the recursion unwinds, point each node’s successor back to it, then clear its old forward link.

Approach

  1. If the list has zero or one node, it is already reversed.
  2. Recursively reverse the list after the head and save its new head.
  3. Point the next node back to the current node.
  4. Set the current node’s next pointer to None to finish the reversed list.
  5. Return the saved new head.
class Solution:
    def reverseList(self, head):
        # An empty or single-node list is already reversed.
        if head is None or head.next is None:
            return head

        # Reverse the remainder of the list.
        new_head = self.reverseList(head.next)

        # Put the current node after its former successor.
        head.next.next = head
        head.next = None

        return new_head

Complexity:

  • Time: O(n), where n is the number of nodes.
  • Space: O(n), for the recursive call stack.

Common follow-ups

  • Can you do it iteratively with O(1) extra space? Use previous, current, and next_node pointers to reverse links while traversing.
  • What if the list is empty or has one node? The base case returns it unchanged.
  • Can you reverse only a portion of the list? Track the sublist boundaries and reconnect them after reversing that segment.
CodingEasyNokiaSoftware Engineer

5. Minimum Cost of Buying Candies With Discount (LeetCode)

Model answer

The task

Given the prices of candies, find the minimum total cost when buying two candies entitles you to a third candy for free. Choose which candies are free to minimize the amount paid.

Key idea

For each group of three, the cheapest candy should be free. Sort prices from highest to lowest, then skip every third price: these are the cheapest candies in each group.

Approach

  1. Sort the prices in descending order.
  2. Scan the sorted prices from highest to lowest.
  3. Add a price to the total unless its position is the third in a group of three.
  4. Return the total.
from typing import List

class Solution:
    def minimumCost(self, cost: List[int]) -> int:
        # In each group of three, the cheapest candy is free.
        prices = sorted(cost, reverse=True)

        total = 0
        for index, price in enumerate(prices):
            if index % 3 != 2:
                total += price

        return total

Complexity:

  • Time: O(n log n), due to sorting the prices.
  • Space: O(n), for the sorted copy of the prices.

Common follow-ups

  • What if only one candy is purchased for every k paid candies? Sort descending and skip every *(k + 1)*-th candy.
  • Can the input list be modified to reduce extra space? Yes; sort it in place, then scan it in reverse.
  • Does the approach work when prices are equal? Yes; any candy among equal-priced items can be free.
CodingEasyNokiaSoftware Engineer

6. Valid Anagram (LeetCode)

Model answer

The task

Determine whether two strings contain the same characters with the same frequencies, regardless of order.

Key idea

Anagrams have identical character counts. Count the characters in each string and compare the resulting frequency maps.

Approach

  1. If the strings have different lengths, return False.
  2. Build a frequency map for each string.
  3. Return whether the maps are equal.
from collections import Counter

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        # Different lengths cannot have matching character counts.
        if len(s) != len(t):
            return False

        # Anagrams have exactly the same character frequencies.
        return Counter(s) == Counter(t)

Complexity:

  • Time: O(n), where n is the length of either string; counting and comparison are linear.
  • Space: O(k), where k is the number of distinct characters stored in the frequency maps.

Common follow-ups

  • Can you do this without two maps? Update one frequency map using s, then decrement counts using t; verify all counts return to zero.
  • What if the input is guaranteed to contain only lowercase English letters? Use a fixed-size array of 26 counters instead of maps.
  • What if sorting is allowed? Sort both strings and compare them; this takes O(n log n) time.
CodingMediumNokiaSoftware Engineer

7. Validate IP Address (LeetCode)

Model answer

The task

Classify a string as an IPv4 address, an IPv6 address, or neither. Each format has its own rules for the number and shape of its components.

Key idea

Check the two formats independently. Splitting on the appropriate separator makes it straightforward to validate both the component count and each component’s characters and numeric or length limits.

Approach

  1. Split on . and check for four IPv4 components.
  2. Require each component to contain only ASCII digits, have no unnecessary leading zero, and represent a value from 0 to 255.
  3. Otherwise, split on : and check for eight IPv6 components.
  4. Require each IPv6 component to contain one to four ASCII hexadecimal characters.
  5. Return the matching classification, or "Neither" if neither check succeeds.
class Solution:
    def validIPAddress(self, queryIP: str) -> str:
        parts = queryIP.split(".")

        if len(parts) == 4:
            valid_ipv4 = True

            for part in parts:
                # IPv4 components must be nonempty ASCII decimal strings.
                if not part or any(ch not in "0123456789" for ch in part):
                    valid_ipv4 = False
                    break

                # Multi-digit components cannot begin with zero.
                if len(part) > 1 and part[0] == "0":
                    valid_ipv4 = False
                    break

                if int(part) > 255:
                    valid_ipv4 = False
                    break

            if valid_ipv4:
                return "IPv4"

        parts = queryIP.split(":")

        if len(parts) == 8:
            hex_digits = "0123456789abcdefABCDEF"

            for part in parts:
                if not 1 <= len(part) <= 4:
                    break
                if any(ch not in hex_digits for ch in part):
                    break
            else:
                return "IPv6"

        return "Neither"

Complexity:

  • Time: O(n), where n is the string length; each character is checked a constant number of times.
  • Space: O(n) for the component lists created by splitting the string.

Common follow-ups

  • How would you support IPv6 :: compression? Allow one compression marker and verify it replaces at least one omitted group.
  • How would you handle IPv4-embedded IPv6 addresses? Parse the final dotted component as IPv4 and count it as two IPv6 groups.
  • What happens with leading zeros in IPv4 components? Reject them unless the component is exactly "0".
CodingMediumNokiaSoftware Engineer

8. LRU Cache (LeetCode)

Model answer

The task

Design a cache with a fixed capacity that supports retrieving and inserting key-value pairs. When an insertion exceeds capacity, evict the item that has gone unused for the longest time.

Key idea

Use a hash map for direct key lookup and a doubly linked list to track recency. Keep the most recently used item at the front; the least recently used item is at the back.

Approach

  1. Create a map from keys to their linked-list nodes.
  2. Use dummy head and tail nodes so items can be added or removed without special cases at the ends.
  3. On a successful get, move the node to the front and return its value; return -1 if the key is absent.
  4. On put, update and promote an existing node, or add a new node at the front.
  5. If the cache is over capacity, remove the node just before the tail and delete its key from the map.
class _Node:
    def __init__(self, key: int = 0, value: int = 0):
        self.key = key
        self.value = value
        self.prev = None
        self.next = None

class LRUCache:
    def __init__(self, capacity: int):
        self.capacity = capacity
        self.nodes = {}

        # Items are stored between these sentinels.
        self.head = _Node()
        self.tail = _Node()
        self.head.next = self.tail
        self.tail.prev = self.head

    def _remove(self, node: _Node) -> None:
        node.prev.next = node.next
        node.next.prev = node.prev

    def _add_to_front(self, node: _Node) -> None:
        node.prev = self.head
        node.next = self.head.next
        self.head.next.prev = node
        self.head.next = node

    def _make_most_recent(self, node: _Node) -> None:
        self._remove(node)
        self._add_to_front(node)

    def get(self, key: int) -> int:
        node = self.nodes.get(key)
        if node is None:
            return -1

        self._make_most_recent(node)
        return node.value

    def put(self, key: int, value: int) -> None:
        node = self.nodes.get(key)

        if node is not None:
            node.value = value
            self._make_most_recent(node)
            return

        node = _Node(key, value)
        self.nodes[key] = node
        self._add_to_front(node)

        if len(self.nodes) > self.capacity:
            least_recent = self.tail.prev
            self._remove(least_recent)
            del self.nodes[least_recent.key]

Complexity:

  • Time: O(1) for get and put; map and list operations take constant time.
  • Space: O(capacity); the map and list store at most the cache’s capacity of entries.

Common follow-ups

  • How would you make the cache thread-safe? Protect operations with a lock.
  • What if entries expire after a time-to-live? Track expiration times and remove expired entries during access or with a cleanup mechanism.
  • How would you support eviction by frequency instead of recency? Track access counts and organize entries by frequency.
CodingMediumNokiaSoftware Engineer

9. Koko Eating Bananas (LeetCode)

Model answer

The task

Given pile sizes and a fixed number of hours, find the smallest integer eating speed that lets Koko finish all the bananas in time. Each pile is handled separately, and any leftover bananas in a pile still take a full hour.

Key idea

Feasibility is monotonic: if a speed works, any faster speed works too. Binary-search the range from 1 to the largest pile, checking each candidate speed by summing the hours needed for every pile.

Approach

  1. Set the search bounds to 1 and the largest pile size.
  2. For a candidate speed, compute each pile’s hours with ceiling division: (pile + speed - 1) // speed.
  3. If the total hours fit within the limit, record the speed and search lower.
  4. Otherwise, search higher.
  5. Return the smallest feasible speed.
class Solution:
    def minEatingSpeed(self, piles: list[int], h: int) -> int:
        left, right = 1, max(piles)

        while left < right:
            speed = (left + right) // 2

            # Check whether this speed finishes all piles in time.
            hours = sum((pile + speed - 1) // speed for pile in piles)

            if hours <= h:
                right = speed
            else:
                left = speed + 1

        return left

Complexity:

  • Time: O(n log m), where n is the number of piles and m is the largest pile; each binary-search check scans the piles.
  • Space: O(1), excluding the input; the check uses only a constant amount of extra space.

Common follow-ups

  • What if the hours limit is smaller than the number of piles? No speed can finish in time, since each nonempty pile takes at least one hour.
  • Can the search bounds be tightened? A lower bound can be derived from total bananas divided by available hours, rounded up.
  • What if piles can be processed in parallel? The feasibility calculation changes to account for concurrent work; this binary search applies when piles are eaten sequentially.
CodingHardNokiaSoftware Engineer

10. Robot Collisions (LeetCode)

Model answer

The task

Simulate robots moving in a line, where a collision occurs when robots moving in opposite directions meet. A collision reduces the health of the survivor by one, or destroys both robots if their healths are equal; return surviving healths in their original input order.

Key idea

Sort robot indices by position, then scan from left to right. A stack of right-moving robots tracks the only robots that can collide with an incoming left-moving robot.

Approach

  1. Sort indices by their robots’ positions.
  2. Push each right-moving robot’s index onto a stack.
  3. For a left-moving robot, resolve collisions with the stack’s top while it is still alive.
  4. Update healths and remove destroyed robots from the stack.
  5. Collect positive healths in original index order.
class Solution:
    def survivedRobotsHealths(
        self,
        positions: list[int],
        healths: list[int],
        directions: str
    ) -> list[int]:
        # Process robots in the order they appear along the line.
        order = sorted(range(len(positions)), key=lambda i: positions[i])
        right_moving = []

        for i in order:
            if directions[i] == "R":
                right_moving.append(i)
                continue

            # A left-moving robot can collide with prior right-moving robots.
            while right_moving and healths[i] > 0:
                j = right_moving[-1]

                if healths[j] < healths[i]:
                    # The right-moving robot is destroyed.
                    healths[i] -= 1
                    healths[j] = 0
                    right_moving.pop()
                elif healths[j] == healths[i]:
                    # Both robots are destroyed.
                    healths[i] = 0
                    healths[j] = 0
                    right_moving.pop()
                else:
                    # The left-moving robot is destroyed.
                    healths[j] -= 1
                    healths[i] = 0

        # The requested order is the original input order.
        return [health for health in healths if health > 0]

Complexity:

  • Time: O(n log n), due to sorting; each robot is pushed and popped at most once.
  • Space: O(n), for the sorted indices and stack.

Common follow-ups

  • What if robots have different speeds? Compute collision times and process events in chronological order.
  • Can the simulation avoid sorting? Only if the input is already ordered by position.
  • What if the output must include surviving robot indices? Collect indices with positive health instead of only their healths.
CodingHardNokiaSoftware Engineer

11. Check If It Is a Good Array (LeetCode)

Model answer

The task

Determine whether integer multiples of some array elements can be added to make exactly 1. Multipliers may be negative, zero, or positive.

Key idea

The integer combinations of the array elements are exactly the multiples of their greatest common divisor. So 1 is possible precisely when the GCD of all elements is 1, by Bézout’s identity.

Approach

  1. Start with a running GCD of 0.
  2. For each number, update the running GCD with the number.
  3. If the final GCD is 1, return True; otherwise return False.
from math import gcd
from typing import List

class Solution:
    def isGoodArray(self, nums: List[int]) -> bool:
        # The running GCD summarizes all integer combinations
        # achievable from the elements seen so far.
        common_divisor = 0

        for number in nums:
            common_divisor = gcd(common_divisor, number)

        return common_divisor == 1

Complexity:

  • Time: O(n log M), where n is the array length and M is its largest value; each GCD calculation takes logarithmic time.
  • Space: O(1), using only a running GCD.

Common follow-ups

  • Can the array form a target k instead of 1? Yes, exactly when the array’s GCD divides k.
  • Can you produce the integer multipliers? Yes; use the extended Euclidean algorithm to track Bézout coefficients.
  • What if the array arrives as a stream? Maintain the running GCD as each value arrives; the same criterion applies.

Practice these out loud, don't memorise them

Reading an answer is not the same as being able to give one under pressure. ChannelPulse plays the interviewer, asks the follow-ups, and scores each answer with feedback and a model answer so you can hear the gap between what you said and what lands.

Get ChannelPulse Browse all questions