Autocoder

Cisco Coding Round Questions with Solutions in Python and Java

Last updated 2026-11-19

Cisco's online assessment combines multiple-choice questions with coding in a proctored 90-minute test. These ten problems practise the parsing, bit manipulation, linked list and queue problems that suit a networking company, plus a classic dynamic programming problem.

Solve each yourself first, then compare with the worked Python and Java solutions.

Problems10, easy to medium
LanguagesPython and Java
PatternsParsing, bit manipulation, lists, stacks, DP
India campus test90 minutes, MCQs and coding, proctored

What Cisco's assessment style suggests

Cisco's India campus programmes describe a 90-minute online assessment with multiple-choice questions and coding, remotely proctored. Cisco does not publish the coding content, but with networking as the company's core business, commonly practised problems touch bit manipulation, string parsing such as IP addresses, linked lists and queues, plus a dynamic programming problem for the harder end. The ten problems below follow that mix and are practice problems, not real test content.

For networking fundamentals and the behavioural interview, see Cisco interview questions.

Mistakes to avoid

Hiring status

Cisco Ideathon 2026 selection closed on 31 August 2026, and Code with Cisco 2026 closed after its code-a-thon on 16 and 17 July 2026. See Cisco hiring for the sourced summary, and check Cisco's India careers site for later editions, which have not been announced.

Cisco Coding Round Questions with Solutions in Python and Java: questions with worked answers

  1. 1

    Valid IPv4 Address: check a dotted-decimal string.

    easy

    Split on dots; there must be exactly four parts, each non-empty, all digits, no leading zero unless the part is exactly '0', and a value from 0 to 255. Time O(n), space O(1). Mistakes: accepting '01' or '256', accepting a plus sign or whitespace (use isdigit on ASCII digits), and splitting on an empty trailing part such as '1.1.1.1.'.

    python
    def valid_ipv4(s):
        parts = s.split('.')
        if len(parts) != 4: return False
        for p in parts:
            if not p or not p.isascii() or not p.isdigit(): return False
            if len(p) > 1 and p[0] == '0': return False
            if int(p) > 255: return False
        return True
    java
    class Solution {
        boolean validIPv4(String s) {
            String[] parts = s.split("\\.", -1);
            if (parts.length != 4) return false;
            for (String p : parts) {
                if (p.isEmpty() || p.length() > 3) return false;
                for (char c : p.toCharArray()) if (c < '0' || c > '9') return false;
                if (p.length() > 1 && p.charAt(0) == '0') return false;
                if (Integer.parseInt(p) > 255) return false;
            }
            return true;
        }
    }
  2. 2

    Restore IP Addresses: all valid ways to split a digit string into an IPv4 address.

    medium

    Backtrack choosing 1 to 3 digits for each of four parts, rejecting parts with leading zeros or values above 255, and accept only if the whole string is consumed after exactly four parts. At most 3^4 branches, so time is effectively constant for the length limit of 12. Mistake: not stopping when the remaining length cannot fit the remaining parts.

    python
    def restore_ip(s):
        res = []
        def go(i, parts):
            if len(parts) == 4:
                if i == len(s): res.append('.'.join(parts))
                return
            for l in (1, 2, 3):
                if i + l > len(s): break
                p = s[i:i+l]
                if (len(p) > 1 and p[0] == '0') or int(p) > 255: continue
                go(i + l, parts + [p])
        go(0, [])
        return res
    java
    import java.util.*;
    class Solution {
        List<String> restoreIp(String s) { List<String> res = new ArrayList<>(); go(s, 0, new ArrayList<>(), res); return res; }
        private void go(String s, int i, List<String> parts, List<String> res) {
            if (parts.size() == 4) { if (i == s.length()) res.add(String.join(".", parts)); return; }
            for (int l = 1; l <= 3 && i + l <= s.length(); l++) {
                String p = s.substring(i, i + l);
                if ((p.length() > 1 && p.charAt(0) == '0') || Integer.parseInt(p) > 255) continue;
                parts.add(p); go(s, i + l, parts, res); parts.remove(parts.size() - 1);
            }
        }
    }
  3. 3

    Reverse Bits of a 32-bit unsigned integer.

    easy

    Loop 32 times: shift the result left by one and append the lowest bit of the input, then shift the input right. Time O(32), which is O(1), space O(1). In Java use the unsigned shift >>> so the sign bit does not spread. Mistake: stopping early when the input becomes zero, which loses the leading zeros that become trailing bits.

    python
    def reverse_bits(n):
        r = 0
        for _ in range(32):
            r = (r << 1) | (n & 1)
            n >>= 1
        return r
    java
    class Solution {
        int reverseBits(int n) {
            int r = 0;
            for (int i = 0; i < 32; i++) { r = (r << 1) | (n & 1); n >>>= 1; }
            return r;
        }
    }
  4. 4

    Number of 1 Bits (Hamming weight).

    easy

    Use Brian Kernighan's trick: n & (n - 1) clears the lowest set bit, so loop until n is zero, counting iterations. Time is the number of set bits, space O(1). This is useful for counting set bits in a subnet mask. Mistake: shifting a negative Java int with >> in a loop that tests n > 0.

    python
    def hamming_weight(n):
        c = 0
        while n:
            n &= n - 1
            c += 1
        return c
    java
    class Solution {
        int hammingWeight(int n) {
            int c = 0;
            while (n != 0) { n &= n - 1; c++; }
            return c;
        }
    }
  5. 5

    Single Number: every element appears twice except one.

    easy

    XOR all elements: x ^ x = 0 and x ^ 0 = x, so the pairs cancel and the unique value remains. Time O(n), space O(1). A hash set works in O(n) space. Mistake: using it when elements can appear three times (needs counting of bits modulo three).

    python
    def single_number(a):
        r = 0
        for x in a: r ^= x
        return r
    java
    class Solution {
        int singleNumber(int[] a) {
            int r = 0;
            for (int x : a) r ^= x;
            return r;
        }
    }
  6. 6

    Power of Two.

    easy

    A positive power of two has exactly one set bit, so n > 0 and n & (n - 1) == 0. Time and space O(1). Mistake: forgetting that zero and negative numbers also satisfy n & (n - 1) == 0 in some cases (0 does), so check n > 0 first. Related to subnet sizes, which are powers of two.

    python
    def is_power_of_two(n):
        return n > 0 and n & (n - 1) == 0
    java
    class Solution {
        boolean isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }
    }
  7. 7

    Merge Two Sorted Linked Lists.

    easy

    Use a dummy head and a tail pointer: repeatedly attach the smaller of the two current nodes and advance that list, then attach whatever remains. Time O(m + n), space O(1) by reusing nodes. Mistake: forgetting to attach the leftover tail, or creating new nodes unnecessarily.

    python
    def merge_two(a, b):
        dummy = tail = ListNode(0)
        while a and b:
            if a.val <= b.val: tail.next, a = a, a.next
            else: tail.next, b = b, b.next
            tail = tail.next
        tail.next = a or b
        return dummy.next
    java
    class ListNode { int val; ListNode next; ListNode(int v) { val = v; } }
    class Solution {
        ListNode mergeTwo(ListNode a, ListNode b) {
            ListNode dummy = new ListNode(0), tail = dummy;
            while (a != null && b != null) {
                if (a.val <= b.val) { tail.next = a; a = a.next; } else { tail.next = b; b = b.next; }
                tail = tail.next;
            }
            tail.next = a != null ? a : b;
            return dummy.next;
        }
    }
  8. 8

    Implement a Queue using two Stacks with amortised O(1) operations.

    medium

    Use an input stack for pushes and an output stack for pops. When the output stack is empty, move every element from the input stack to it, reversing the order so the oldest is on top. Each element is moved at most once, so pop and peek are amortised O(1). Mistake: moving elements on every pop, which makes it O(n), or moving while the output stack still has items.

    python
    class MyQueue:
        def __init__(self):
            self.inp, self.out = [], []
        def push(self, x):
            self.inp.append(x)
        def _shift(self):
            if not self.out:
                while self.inp: self.out.append(self.inp.pop())
        def pop(self):
            self._shift(); return self.out.pop()
        def peek(self):
            self._shift(); return self.out[-1]
        def empty(self):
            return not self.inp and not self.out
    java
    import java.util.*;
    class MyQueue {
        private final Deque<Integer> in = new ArrayDeque<>(), out = new ArrayDeque<>();
        void push(int x) { in.push(x); }
        private void shift() { if (out.isEmpty()) while (!in.isEmpty()) out.push(in.pop()); }
        int pop() { shift(); return out.pop(); }
        int peek() { shift(); return out.peek(); }
        boolean empty() { return in.isEmpty() && out.isEmpty(); }
    }
  9. 9

    String Compression (run-length encoding): replace runs with the character and count.

    medium

    Scan runs of equal characters; write the character, and the count only if it is greater than one, splitting multi-digit counts into digits. Return the new length, using a write pointer so it is done in place. Time O(n), space O(1). Mistake: writing '1' for single characters, or forgetting to flush the final run after the loop.

    python
    def compress(chars):
        w = i = 0
        while i < len(chars):
            j = i
            while j < len(chars) and chars[j] == chars[i]: j += 1
            chars[w] = chars[i]; w += 1
            if j - i > 1:
                for d in str(j - i):
                    chars[w] = d; w += 1
            i = j
        return w
    java
    class Solution {
        int compress(char[] chars) {
            int w = 0, i = 0;
            while (i < chars.length) {
                int j = i;
                while (j < chars.length && chars[j] == chars[i]) j++;
                chars[w++] = chars[i];
                if (j - i > 1) for (char d : String.valueOf(j - i).toCharArray()) chars[w++] = d;
                i = j;
            }
            return w;
        }
    }
  10. 10

    Longest Common Subsequence of two strings.

    medium

    DP table where dp[i][j] is the LCS length of the first i characters of a and first j of b: if the characters match it is dp[i-1][j-1] + 1, otherwise the maximum of dp[i-1][j] and dp[i][j-1]. Time O(m n), space O(m n), reducible to O(min(m, n)) with two rows. Mistake: confusing subsequence with substring; a subsequence need not be contiguous. See dynamic programming interview questions.

    python
    def lcs(a, b):
        m, n = len(a), len(b)
        dp = [[0] * (n + 1) for _ in range(m + 1)]
        for i in range(1, m + 1):
            for j in range(1, n + 1):
                dp[i][j] = dp[i-1][j-1] + 1 if a[i-1] == b[j-1] else max(dp[i-1][j], dp[i][j-1])
        return dp[m][n]
    java
    class Solution {
        int lcs(String a, String b) {
            int m = a.length(), n = b.length();
            int[][] dp = new int[m + 1][n + 1];
            for (int i = 1; i <= m; i++)
                for (int j = 1; j <= n; j++)
                    dp[i][j] = a.charAt(i - 1) == b.charAt(j - 1) ? dp[i - 1][j - 1] + 1 : Math.max(dp[i - 1][j], dp[i][j - 1]);
            return dp[m][n];
        }
    }

Frequently asked questions

Are Cisco coding questions hard?

Commonly practised at easy to medium level, with the time pressure of a combined multiple-choice and coding test.

Which language should I use?

Use the one allowed and fastest for you. Python and Java both work for all ten problems here.

Do I need bit manipulation for Cisco?

It is useful: subnet masks, flags and checksums use bit operations, and these problems are common practice.

Sources

Related guides

More in Company Interview Questions

See all in this section