InternDoor

IBM interview prep

20 practice questions on the topics candidates reported from IBM interviews, with answers. The questions are ours; each one links to the interview report that names its topic.

Practise them as a timed round7 roles open at IBM

DSA 6

  1. DSAMedium

    What is the time complexity of inserting one element into a binary heap of n elements?

    1. O(n log n)
    2. O(1)
    3. O(n)
    4. O(log n)
    Show the answer

    D. O(log n)

    The new element goes at the end and is swapped upward while it beats its parent. The heap is a complete tree of height log n, so there are at most log n swaps.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2025, on GeeksforGeeks.

  2. DSAEasy

    Merge sort splits the array in half, sorts each half and merges them. What is its time complexity, and its extra space for an array?

    1. O(n log n) time in every case, with O(n) extra space for merging
    2. O(n^2) time in the worst case, with O(1) extra space
    3. O(n) time, with O(log n) extra space
    4. O(n log n) time on average but O(n^2) in the worst case
    Show the answer

    A. O(n log n) time in every case, with O(n) extra space for merging

    There are log n levels of halving and each level merges n elements, whatever the input order. Merging needs a temporary array. Quick sort is the one that degrades to O(n^2).

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2021, on GeeksforGeeks.

  3. DSAMedium

    Houses in a row hold 2, 7, 9, 3, 1. A thief cannot rob two adjacent houses. What is the most they can take?

    1. 11
    2. 10
    3. 12
    4. 13
    Show the answer

    C. 12

    best[i] = max(best[i-1], best[i-2] + house[i]) gives 2, 7, 11, 11, 12. Robbing houses 1, 3 and 5 (2 + 9 + 1) is 12. This is LeetCode 198, and it needs only two running values, so O(n) time and O(1) space.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2025, on GeeksforGeeks.

  4. DSAMedium

    What is the longest palindromic substring of "forgeeksskeegfor"?

    1. "geeksskeeg"
    2. "forgeeksskeegfor"
    3. "eeksskee"
    4. "ksk"
    Show the answer

    A. "geeksskeeg"

    Expanding around each centre (the gap between the two s characters here) grows "ss" to "kssk", "eksske", "eeksskee" and "geeksskeeg", then stops at "r" versus "f". The whole string is not a palindrome. Expand-around-centre is O(n^2) time and O(1) space.

    This topic is named in a candidate’s interview report: ISDL software developer on-campus interview, 2022, on GeeksforGeeks.

  5. DSAMedium

    In a doubly linked list, you delete node x, which is neither the head nor the tail. Which updates are needed?

    1. x.prev.next = x.next only
    2. x.next = null and x.prev = null only
    3. x.prev.next = x.next and x.next.prev = x.prev
    4. Walk from the head to find the node before x, then relink
    Show the answer

    C. x.prev.next = x.next and x.next.prev = x.prev

    Both neighbours must skip x: the previous node's next and the next node's prev. No walk is needed because x already knows both neighbours, so deletion is O(1). Deleting the head or tail also moves the head or tail pointer.

    This topic is named in a candidate’s interview report: ISDL software developer on-campus interview, 2022, on GeeksforGeeks.

  6. DSAEasy

    A singly linked list is circular if its last node points back to the head. How do you check that with no extra memory?

    1. Walk from head.next until you reach null (not circular) or the head again (circular)
    2. Count the nodes and compare with a stored length
    3. Sort the list and look for duplicates
    4. Check whether the head's value appears twice
    Show the answer

    A. Walk from head.next until you reach null (not circular) or the head again (circular)

    For a list that is either a plain list or a full circle, one walk settles it in O(n) time and O(1) space. If the loop could start in the middle instead, a walk would never meet the head again, and you need fast and slow pointers (Floyd) to find it.

    This topic is named in a candidate’s interview report: Software developer internship interview, 2023, on GeeksforGeeks.

Python 2

  1. PythonMedium

    What does this print?

    def squeeze(s):
        out, i = [], 0
        while i < len(s):
            j = i
            while j < len(s) and s[j] == s[i]:
                j += 1
            out.append(s[i] + (str(j - i) if j - i > 1 else ''))
            i = j
        return ''.join(out)
    
    print(squeeze("abbcddeee"))
    1. ab2cd2e3
    2. a1b2c1d2e3
    3. abcde
    4. a1b1b1c1d1d1e1e1e1
    Show the answer

    A. ab2cd2e3

    Each run of equal characters becomes the character, followed by the run length only when the run is longer than one. So a, bb, c, dd, eee become a, b2, c, d2, e3. One pass, O(n).

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2025, on GeeksforGeeks.

  2. PythonEasy

    What does this print?

    import string
    
    def is_pangram(s):
        return set(string.ascii_lowercase) <= set(s.lower())
    
    print(is_pangram("The quick brown fox jumps over the lazy dog"),
          is_pangram("Hello world"))
    1. True False
    2. True True
    3. False False
    4. False True
    Show the answer

    A. True False

    A pangram uses every letter at least once. <= on sets asks whether all 26 letters are in the sentence's letters; the fox sentence has them all, "Hello world" does not. Lower-casing first makes the check case-insensitive.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2021, on GeeksforGeeks.

C and C++ 6

  1. C and C++Hard

    Which statement about std::unique_ptr and std::shared_ptr is true?

    1. shared_ptr frees the object as soon as any owner goes out of scope
    2. Both can be copied freely
    3. unique_ptr counts references and shared_ptr does not
    4. unique_ptr has one owner and can be moved but not copied; shared_ptr counts its owners and frees the object when the last one goes
    Show the answer

    D. unique_ptr has one owner and can be moved but not copied; shared_ptr counts its owners and frees the object when the last one goes

    unique_ptr expresses sole ownership with no runtime overhead, and std::move transfers it. shared_ptr keeps a reference count, which costs an extra allocation and atomic updates. Two shared_ptrs pointing at each other leak; weak_ptr breaks such cycles.

    This topic is named in a candidate’s interview report: Software developer internship interview, 2023, on GeeksforGeeks.

  2. C and C++Medium

    What does this print?

    #include <iostream>
    
    struct Box {
        int* v;
        Box(int x) : v(new int(x)) {}
    };
    
    int main() {
        Box a(5);
        Box b = a;      // the copy the compiler writes
        *b.v = 9;
        std::cout << *a.v << " " << *b.v << std::endl;
    }
    1. 5 9
    2. It does not compile
    3. 5 5
    4. 9 9
    Show the answer

    D. 9 9

    The compiler-written copy constructor copies the pointer, not the int it points to: a shallow copy. a.v and b.v point at the same int, so writing 9 through b changes a too. A deep copy would allocate a new int in a copy constructor of its own (and the class would also need a destructor and copy assignment, the rule of three).

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2025, on GeeksforGeeks.

  3. C and C++Medium

    A base class declares virtual void draw(). Besides the function being virtual, what does a call need for the derived class's draw() to run?

    1. The derived class must also be declared virtual
    2. The function must be static
    3. The call must go through a pointer or reference to the base class, not a base object copied by value
    4. The derived class must call draw() from its constructor
    Show the answer

    C. The call must go through a pointer or reference to the base class, not a base object copied by value

    Dynamic dispatch happens when draw() is called through a Base* or Base&. Assigning a Derived to a plain Base object slices it down to a Base, so the call is resolved statically and Base::draw() runs. The derived function also has to override it with the same signature.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2025, on GeeksforGeeks.

  4. C and C++Medium

    How does a typical C++ compiler implement virtual functions?

    1. Each object stores a copy of every virtual function's code
    2. The linker rewrites every call site when the program starts
    3. The call is decided at compile time from the declared type
    4. Each class with virtual functions gets a table of function pointers (the v-table), and each object holds a hidden pointer to its class's table
    Show the answer

    D. Each class with virtual functions gets a table of function pointers (the v-table), and each object holds a hidden pointer to its class's table

    The v-table is one per class, the hidden vptr one per object. A virtual call loads the vptr, picks the slot for that function and jumps there, which is why the derived version runs through a base pointer. The standard does not require this scheme, but it is what GCC, Clang and MSVC do.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2025, on GeeksforGeeks.

  5. C and C++Medium

    What is the difference between a linker and a loader?

    1. They are two names for the same program
    2. The loader compiles source code; the linker runs it
    3. The linker joins object files and libraries into one executable and resolves symbols between them; the loader puts that executable into memory and starts it
    4. The linker runs at run time, the loader at compile time
    Show the answer

    C. The linker joins object files and libraries into one executable and resolves symbols between them; the loader puts that executable into memory and starts it

    Compile turns each .c file into an object file with unresolved references; the linker (ld) matches every call to its definition and writes the executable. When you run it, the OS loader maps it into memory, loads any shared libraries through the dynamic linker, and jumps to the entry point.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2021, on GeeksforGeeks.

  6. C and C++Easy

    What does a standard C header such as stdio.h usually contain?

    1. The compiled machine code of printf
    2. The source code of every function it names
    3. Only comments describing the functions
    4. Declarations: function prototypes, macros, types and constants; the compiled code is in the C library, linked in later
    Show the answer

    D. Declarations: function prototypes, macros, types and constants; the compiled code is in the C library, linked in later

    #include pastes the header in, so the compiler knows printf's signature. The code itself lives in libc and is joined by the linker. On Linux the system headers are found in include paths such as /usr/include.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2021, on GeeksforGeeks.

Operating systems 1

  1. Operating systemsEasy

    Which statement about stack and heap memory is true?

    1. The stack holds each call's frame (locals, return address) and is freed when the call returns; the heap holds memory allocated at run time that lives until it is freed or collected
    2. Heap memory is freed automatically when a function returns
    3. The stack is always larger than the heap
    4. Only global variables live on the stack
    Show the answer

    A. The stack holds each call's frame (locals, return address) and is freed when the call returns; the heap holds memory allocated at run time that lives until it is freed or collected

    Stack allocation is a pointer bump and is undone on return, which is why returning the address of a local is a bug. Heap memory (malloc, new) outlives the call and must be freed, or in Java and Python reclaimed by the garbage collector. Deep recursion overflows the stack, not the heap.

    This topic is named in a candidate’s interview report: Software developer internship interview, 2023, on GeeksforGeeks.

Web development 1

  1. Web developmentEasy

    What does this print?

    const row = [1, "two", true, null, undefined];
    console.log(JSON.stringify(row));
    1. [1,"two",true,null,undefined]
    2. [1,"two",true,null]
    3. [1,two,true,null]
    4. [1,"two",true,null,null]
    Show the answer

    D. [1,"two",true,null,null]

    JSON has no undefined, so inside an array JSON.stringify writes it as null to keep the positions. Strings are quoted, numbers, booleans and null are written as they are. In an object, a property holding undefined is left out instead.

    This topic is named in a candidate’s interview report: ISDL software developer on-campus interview, 2022, on GeeksforGeeks.

Software engineering 1

  1. Software engineeringMedium

    You are building a URL shortener. What sits at its core?

    1. A sorted list of long URLs searched with binary search
    2. A new DNS record for every short link
    3. A compression algorithm applied to the URL text
    4. A key-value map from a short code to the long URL, with codes from a counter encoded in base 62 or from a hash of the URL
    Show the answer

    D. A key-value map from a short code to the long URL, with codes from a counter encoded in base 62 or from a hash of the URL

    Lookup is by exact code, so a hash table (or a key-value store) gives O(1) average reads. A counter in base 62 never collides; a truncated hash needs a collision check. The redirect is then a 301 or 302 to the stored URL.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2025, on GeeksforGeeks.

Aptitude 3

  1. AptitudeMedium

    Two ropes each take exactly one hour to burn, but they burn unevenly, so half a rope is not half an hour. How do you measure 45 minutes?

    1. Burn one rope and stop when it is three quarters gone
    2. Fold one rope in four and burn one quarter
    3. Light both ropes at one end and wait for both to finish
    4. Light rope A at both ends and rope B at one end; when A burns out, light B's other end; B burns out 15 minutes later
    Show the answer

    D. Light rope A at both ends and rope B at one end; when A burns out, light B's other end; B burns out 15 minutes later

    A rope lit at both ends burns out in 30 minutes, however unevenly it burns. At that moment B has 30 minutes left; lighting its other end halves that to 15. 30 + 15 = 45. Anything based on length fails because the burn rate is uneven.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2025, on GeeksforGeeks.

  2. AptitudeEasy

    What is the minimum number of straight cuts that divides a round cake into 8 equal pieces?

    1. 3
    2. 4
    3. 8
    4. 2
    Show the answer

    A. 3

    Two perpendicular vertical cuts through the centre give 4 equal pieces, and one horizontal cut through the middle of the cake's height halves all four at once. Each cut can at most double the pieces here, and 2 x 2 x 2 = 8.

    This topic is named in a candidate’s interview report: ISDL software developer on-campus interview, 2022, on GeeksforGeeks.

  3. AptitudeMedium

    Of 12 identical-looking coins, one is fake and lighter. With a balance scale, what is the fewest weighings that always finds it?

    1. 2
    2. 4
    3. 3
    4. 6
    Show the answer

    C. 3

    Each weighing has three outcomes (left lighter, right lighter, balance), so k weighings can tell apart at most 3^k coins. 3^2 = 9 is fewer than 12, and 3^3 = 27 is enough: weigh 4 against 4, keep the group of 4 with the fake, then 1 against 1 twice at most.

    This topic is named in a candidate’s interview report: Software developer on-campus interview, 2025, on GeeksforGeeks.

Prep for other employers

All employers
See who is hiring after IBM

Engineering internships and entry-level jobs in India, newest first.