Freshworks interview questions & answers

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

CodingEasyFreshworksSoftware Engineer

1. Two Sum (LeetCode)

Model answer

The task

Given a list of integers and a target, return the indices of two distinct elements whose values add up to the target. The usual version guarantees a valid pair.

Key idea

As we scan the list, store each value’s index in a hash table. For the current value, check whether its needed complement has already appeared; this finds a pair in one pass.

Approach

  1. Create a dictionary mapping previously seen values to their indices.
  2. For each element, compute the complement needed to reach the target.
  3. If that complement is in the dictionary, return its stored index and the current index.
  4. Otherwise, store the current value and index, then continue.
from typing import List

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        # Map each value already visited to its index.
        seen = {}

        for index, value in enumerate(nums):
            complement = target - value

            # A match must come from an earlier, distinct element.
            if complement in seen:
                return [seen[complement], index]

            seen[value] = index

        # The standard problem guarantees a solution.
        raise ValueError("No two elements sum to the target")

Complexity:

  • Time: O(n), where n is the number of elements; each lookup and insertion is O(1) on average.
  • Space: O(n), for the dictionary of values seen so far.

Common follow-ups

  • What if there may be multiple valid pairs? Return the first pair found, or keep searching and collect pairs according to the required output rules.
  • What if the input is sorted? Use two pointers from opposite ends for O(1) extra space; preserve original indices if those are required.
  • What if values repeat? The dictionary stores indices, and checking before insertion ensures the current element is not paired with itself.
CodingEasyFreshworksSoftware Engineer

2. 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.
CodingMediumFreshworksSoftware Engineer

3. Search in Rotated Sorted Array (LeetCode)

Model answer

The task

Given an ascending array that has been rotated at an unknown position, find the index of a target value, or return -1 if it is absent. The values are distinct.

Key idea

At each binary-search step, at least one half of the current range is still sorted. Check whether the target falls within that half; if so, keep it, otherwise search the other half.

Approach

  1. Initialize two pointers at the ends of the array.
  2. While the pointers have not crossed, inspect the middle value.
  3. If it matches the target, return its index.
  4. If the left half is sorted, check whether the target lies within its bounds and discard the other half if it does.
  5. Otherwise, use the sorted right half in the same way.
  6. Return -1 if the range becomes empty.
class Solution:
    def search(self, nums: list[int], target: int) -> int:
        left, right = 0, len(nums) - 1

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

            if nums[mid] == target:
                return mid

            # The left half is sorted.
            if nums[left] <= nums[mid]:
                if nums[left] <= target < nums[mid]:
                    right = mid - 1
                else:
                    left = mid + 1
            # Otherwise, the right half is sorted.
            else:
                if nums[mid] < target <= nums[right]:
                    left = mid + 1
                else:
                    right = mid - 1

        return -1

Complexity:

  • Time: O(log n), because each step discards about half the remaining range.
  • Space: O(1), since the search uses only a fixed number of variables.

Common follow-ups

  • What changes if duplicates are allowed? If the endpoints and midpoint are equal, discard one endpoint; worst-case time can become O(n).
  • How would you find the rotation pivot? Binary-search for the minimum element, then search the appropriate sorted portion.
  • How would you return all matching indices with duplicates? First locate a match, then scan outward across adjacent equal values.
CodingMediumFreshworksSoftware Engineer

4. Container With Most Water (LeetCode)

Model answer

The task

Given nonnegative heights arranged along a line, choose two positions to form a container with the greatest possible area. Its area is the distance between the positions multiplied by the shorter of their two heights.

Key idea

Start with the widest possible pair, at the two ends. The shorter side limits the area, so moving the taller side inward cannot improve that limiting height and only reduces the width. Move the shorter side instead, hoping to find a taller boundary.

Approach

  1. Set pointers to the first and last positions.
  2. Compute the area using their distance and the shorter height; update the best area.
  3. Move the pointer at the shorter height inward by one position.
  4. Repeat until the pointers meet.
  5. Return the greatest area seen.
from typing import List

class Solution:
    def maxArea(self, height: List[int]) -> int:
        left = 0
        right = len(height) - 1
        best_area = 0

        while left < right:
            width = right - left
            limiting_height = min(height[left], height[right])
            best_area = max(best_area, width * limiting_height)

            # The shorter side limits this container's area.
            # Moving the taller side inward cannot improve that limit.
            if height[left] <= height[right]:
                left += 1
            else:
                right -= 1

        return best_area

Complexity:

  • Time: O(n), because each pointer moves inward at most n times.
  • Space: O(1), since only a few variables are used.

Common follow-ups

  • What if heights can be negative? A negative height does not describe a valid container; clarify the input rules, or treat invalid heights as unusable.
  • Why is it safe to discard the shorter side? With the same shorter boundary, every inward pair has less width, so it cannot produce a larger area.
  • Can this be done with extra memory? Not usefully for this objective; the two-pointer scan already processes the candidates in linear time with constant space.
CodingMediumFreshworksSoftware Engineer

5. Product of Array Except Self (LeetCode)

Model answer

The task

Given an integer array, return an array where each position contains the product of every input value except the one at that same position. Do so without division.

Key idea

For each position, multiply the product of all values to its left by the product of all values to its right. Store left products in the result, then accumulate right products in a second pass.

Approach

  1. Create a result array initialized to 1.
  2. Scan from left to right, storing the product of values seen before each position.
  3. Scan from right to left, multiplying each result by the product of values after that position.
  4. Update the running right-side product after processing each position.
from typing import List

class Solution:
    def productExceptSelf(self, nums: List[int]) -> List[int]:
        n = len(nums)
        result = [1] * n

        # Store the product of all elements to the left of each index.
        left_product = 1
        for i in range(n):
            result[i] = left_product
            left_product *= nums[i]

        # Multiply by the product of all elements to the right.
        right_product = 1
        for i in range(n - 1, -1, -1):
            result[i] *= right_product
            right_product *= nums[i]

        return result

Complexity:

  • Time: O(n), with two passes over the array.
  • Space: O(1) auxiliary space, excluding the result array.

Common follow-ups

  • What if the array contains zeros? The same method works without special cases.
  • Can this be done with division? Division requires careful handling of zeros and may be disallowed; the two-pass method avoids it.
  • Can the result be computed in place? The output array already stores the left products, then is updated with right products.
CodingMediumFreshworksSoftware Engineer

6. Meeting Rooms II (LeetCode)

Model answer

The task

Given meeting time intervals, find the minimum number of rooms needed so that no overlapping meetings share a room.

Key idea

Process meetings in start-time order. Track each occupied room by the time its meeting ends; a room is available when its meeting ends no later than the next meeting starts.

Approach

  1. Sort intervals by start time.
  2. Keep a min-heap of end times for meetings using rooms.
  3. For each meeting, remove the earliest end time if that room is available.
  4. Add the current meeting’s end time to the heap.
  5. The largest heap size reached is the minimum room count.
import heapq
from typing import List

class Solution:
    def minMeetingRooms(self, intervals: List[List[int]]) -> int:
        if not intervals:
            return 0

        intervals.sort(key=lambda meeting: meeting[0])
        room_end_times = []

        for start, end in intervals:
            # Reuse the room whose meeting finishes first, if available.
            if room_end_times and room_end_times[0] <= start:
                heapq.heappop(room_end_times)

            heapq.heappush(room_end_times, end)

        return len(room_end_times)

Complexity:

  • Time: O(n log n), for sorting and heap operations across n meetings.
  • Space: O(n), for the heap in the worst case.

Common follow-ups

  • What if a meeting ending at time t overlaps one starting at t? Change the availability check from <= to <.
  • How can you return a room assignment for every meeting? Store (end_time, room_id) in the heap and reuse the freed room ID.
  • How would you handle meetings arriving online? Maintain the end-time heap as meetings arrive; each new meeting can reuse a room or add one.
CodingMediumFreshworksSoftware Engineer

7. Remove Duplicates from Sorted Array II (LeetCode)

Model answer

The task

Given a sorted array, modify it in place so each value appears at most twice. Return the length of the retained prefix; values beyond that prefix do not matter.

Key idea

Because the array is sorted, duplicates are adjacent. Keep a value only if fewer than two values have already been written, or if it differs from the value two positions behind the write pointer.

Approach

  1. Use write to track the next position in the retained prefix.
  2. Scan each value from left to right.
  3. Accept it when write < 2 or it differs from nums[write - 2].
  4. Write accepted values at nums[write] and advance write.
  5. Return write.
from typing import List

class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        # The first two values can always be kept.
        write = 0

        for value in nums:
            # Keep the value only if it would not make three equal
            # values consecutive in the retained, sorted prefix.
            if write < 2 or value != nums[write - 2]:
                nums[write] = value
                write += 1

        return write

Complexity:

  • Time: O(n), where n is the array length; each value is examined once.
  • Space: O(1), since the array is updated in place.

Common follow-ups

  • Allow each value at most m times: Compare with nums[write - m], accepting unconditionally while write < m.
  • What if the input is not sorted? This adjacent-value check no longer works; use a frequency map if extra space is allowed.
  • Can the same approach remove all duplicates? Yes. Keep a value only when it differs from the last retained value.
CodingMediumFreshworksSoftware Engineer

8. Group Anagrams (LeetCode)

Model answer

The task

Partition the input strings into groups so that strings in the same group contain the same characters with the same frequencies. The order of the groups does not matter.

Key idea

Sort the characters of each string to create a canonical key. Anagrams produce the same key, so a hash table can collect them together.

Approach

  1. Create a mapping from canonical keys to lists of original strings.
  2. For each string, sort its characters and use the result as its key.
  3. Append the string to the list for that key.
  4. Return all grouped lists.
from collections import defaultdict
from typing import List

class Solution:
    def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
        groups = defaultdict(list)

        for word in strs:
            # Anagrams have identical sorted-character representations.
            key = "".join(sorted(word))
            groups[key].append(word)

        return list(groups.values())

Complexity:

  • Time: O(n · k log k), where n is the number of strings and k is the maximum string length.
  • Space: O(n · k) to store the grouped strings and their keys.

Common follow-ups

  • Can this be faster for a fixed alphabet? Use a character-frequency tuple as the key, computing it in O(k) per string.
  • Does this work with uppercase letters or Unicode? Yes; sorting characters works for any Python strings.
  • Can groups be returned in a deterministic order? Sort the groups, or their keys, before returning them.
  • What if memory is limited? Consider processing input in batches or grouping externally by canonical key.
CodingMediumFreshworksSoftware Engineer

9. Longest Substring Without Repeating Characters (LeetCode)

Model answer

The task

Find the length of the longest contiguous section of a string in which every character appears at most once.

Key idea

Maintain a sliding window with no repeated characters. When a character repeats within the window, move the left edge just past its previous occurrence.

Approach

  1. Track each character’s most recent index in a dictionary.
  2. Keep left as the window’s starting index and best as its longest length so far.
  3. For each character, move left forward if its previous occurrence is inside the current window.
  4. Record the character’s current index and update best using the window length.
class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        last_seen = {}
        left = 0
        best = 0

        for right, char in enumerate(s):
            # Skip past a repeated character if it is in the current window.
            if char in last_seen and last_seen[char] >= left:
                left = last_seen[char] + 1

            last_seen[char] = right
            best = max(best, right - left + 1)

        return best

Complexity:

  • Time: O(n), because each character is processed once.
  • Space: O(k), where k is the number of distinct characters encountered.

Common follow-ups

  • Return the substring itself: store the best window’s start and end indices when updating best.
  • Handle a stream of characters: keep the same window state and process each arriving character incrementally.
  • Use a fixed-size character set: replace the dictionary with an array of last-seen indices.
CodingHardFreshworksSoftware Engineer

10. Merge k Sorted Lists (LeetCode)

Model answer

The task

Combine several individually sorted linked lists into one sorted linked list. The result should reuse the input nodes rather than create a new node for every value.

Key idea

Keep the first unmerged node from each nonempty list in a min-heap. Repeatedly take the smallest node, append it to the result, and add its successor to the heap.

Approach

  1. Add each nonempty list’s head to the heap.
  2. Include a unique counter in each heap entry so equal values never require comparing nodes.
  3. Pop the smallest node and append it to the result.
  4. If that node has a successor, push the successor into the heap.
  5. Return the node after a dummy head.
import heapq
from typing import Optional

class ListNode:
    def __init__(self, val: int = 0, next: Optional["ListNode"] = None):
        self.val = val
        self.next = next

class Solution:
    def mergeKLists(
        self, lists: list[Optional[ListNode]]
    ) -> Optional[ListNode]:
        heap = []
        serial = 0  # Break ties without comparing ListNode objects.

        for node in lists:
            if node is not None:
                heapq.heappush(heap, (node.val, serial, node))
                serial += 1

        dummy = ListNode()
        tail = dummy

        while heap:
            _, _, node = heapq.heappop(heap)
            tail.next = node
            tail = node

            if node.next is not None:
                heapq.heappush(heap, (node.next.val, serial, node.next))
                serial += 1

        tail.next = None
        return dummy.next

Complexity:

  • Time: O(N log k), where each of the N nodes is pushed and popped once.
  • Space: O(k) for the heap, which holds at most one node per input list.

Common follow-ups

  • How can divide and conquer solve this? Merge lists in pairs over successive rounds, also taking O(N log k) time.
  • What if the lists are supplied as a stream? Keep one current node per active list in the heap and add lists as they arrive.
  • Can the inputs be modified? Yes; this solution relinks and reuses their nodes.

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