InternDoor

HPE interview prep

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

Practise them as a timed round

DSA 5

  1. DSAEasy

    Two pointers start at the head of a singly linked list. Each step, one moves one node and the other moves two. When the fast one reaches the end, where is the slow one?

    1. At the head
    2. At the middle node
    3. At the last node
    4. At the second node
    Show the answer

    B. At the middle node

    The fast pointer covers twice the distance, so the slow one has gone half way. This finds the middle in one traversal; for an even length it lands on the first or second middle depending on the exact loop condition.

    This topic is named in a candidate’s interview report: Aruba and R&D intern on-campus interview, 2021, on GeeksforGeeks.

  2. DSAEasy

    Which of these runs in O(log n) time on n items?

    1. Binary search for a key in a sorted array
    2. Finding the largest value in an unsorted array
    3. Comparing every pair of elements
    4. Printing every element
    Show the answer

    A. Binary search for a key in a sorted array

    Binary search halves what is left on every step, so it needs about log2 n steps: 20 steps for a million items. A scan of every element is O(n), and comparing every pair is O(n^2). n is the size of the input.

    This topic is named in a candidate’s interview report: IT developer intern on-campus interview, 2024, on GeeksforGeeks.

  3. DSAMedium

    A stepping number is one whose adjacent digits differ by exactly 1, such as 21 or 123. How many stepping numbers lie between 10 and 30, inclusive?

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

    A. 4

    They are 10, 12, 21 and 23. A BFS or DFS that grows numbers digit by digit (from d, append d - 1 or d + 1) generates them directly instead of testing every number in the range.

    This topic is named in a candidate’s interview report: Software development and QA on-campus interview, 2022, on GeeksforGeeks.

  4. DSAMedium

    On an infinite grid you can move one step in any of 8 directions, diagonals included. What is the fewest steps to go from (0, 0) to (3, 4) and then to (1, 1)?

    1. 7
    2. 14
    3. 9
    4. 6
    Show the answer

    A. 7

    With diagonal moves, the steps between two points are max(|dx|, |dy|), since a diagonal covers one unit of each. (0, 0) to (3, 4) takes 4, and (3, 4) to (1, 1) takes max(2, 3) = 3, so 7 in all.

    This topic is named in a candidate’s interview report: Software development and QA on-campus interview, 2022, on GeeksforGeeks.

  5. DSAMedium

    A sorted array may hold negatives, such as [-4, -1, 0, 3, 10]. How do you return the squares in sorted order in O(n)?

    1. Square every element; the result is already sorted
    2. Square every element and sort: O(n) on average
    3. Two pointers at both ends: the larger absolute value gives the next-largest square, written from the back of the result
    4. Binary search for every square
    Show the answer

    C. Two pointers at both ends: the larger absolute value gives the next-largest square, written from the back of the result

    The largest squares sit at the two ends, so compare |a[left]| with |a[right]|, place the larger square at the end of the output and move that pointer inward. Squaring then sorting works but costs O(n log n). Here the result is [0, 1, 9, 16, 100].

    This topic is named in a candidate’s interview report: Software development and QA on-campus interview, 2022, on GeeksforGeeks.

Python 4

  1. PythonEasy

    In a try statement, which block runs whether or not an exception was raised?

    1. except
    2. else
    3. finally
    4. raise
    Show the answer

    C. finally

    finally always runs, which makes it the place to release resources. except runs only on a matching exception and else only when no exception happened.

    This topic is named in a candidate’s interview report: Software development and QA on-campus interview, 2022, on GeeksforGeeks.

  2. PythonEasy

    What does this print?

    s = "HPE-2023 is Great!"
    print("".join(c for c in s if c.islower() or c.isdigit()))
    1. 2023isGreat
    2. HPE2023isGreat
    3. 2023isreat
    4. 2023 is reat
    Show the answer

    C. 2023isreat

    Only lower-case letters and digits survive: capitals (H, P, E, G), the hyphen, the spaces and the ! are all dropped. islower is false for a capital and for anything that is not a letter.

    This topic is named in a candidate’s interview report: Software development and QA on-campus interview, 2022, on GeeksforGeeks.

  3. PythonEasy

    How does a Python tuple differ from a list?

    1. A tuple can only hold numbers
    2. Lists are always faster
    3. A tuple is immutable, so it can be a dictionary key or a set member when its items are hashable; a list can change in place
    4. Tuples cannot be indexed
    Show the answer

    C. A tuple is immutable, so it can be a dictionary key or a set member when its items are hashable; a list can change in place

    Both are ordered and indexable. Because a tuple cannot change, it is hashable (if its contents are) and slightly lighter in memory, which suits fixed records like (x, y). A list suits a collection you append to.

    This topic is named in a candidate’s interview report: R&D intern on-campus interview, 2020, on GeeksforGeeks.

  4. PythonMedium

    What does this print?

    def set_bits(n):
        count = 0
        while n:
            n &= n - 1
            count += 1
        return count
    
    print(set_bits(29), set_bits(64))
    1. 3 1
    2. 5 1
    3. 4 6
    4. 4 1
    Show the answer

    D. 4 1

    29 is 11101 in binary, four 1 bits; 64 is 1000000, one. n & (n - 1) clears the lowest set bit, so the loop runs once per 1 bit rather than once per bit (Brian Kernighan's method). Python also has bin(n).count("1") and, from 3.10, n.bit_count().

    This topic is named in a candidate’s interview report: R&D intern on-campus interview, 2020, on GeeksforGeeks.

C and C++ 4

  1. C and C++Medium

    In a C program, a function declares static int calls = 0; inside it. Where is calls stored?

    1. On the stack, created fresh on every call
    2. On the heap, freed when the function returns
    3. With the globals, in the data area (BSS here, since it starts at zero); it keeps its value between calls
    4. Only in a CPU register
    Show the answer

    C. With the globals, in the data area (BSS here, since it starts at zero); it keeps its value between calls

    Static and global variables live for the whole run, in the data segment, or BSS when they start at zero. Ordinary local variables sit on the stack and vanish when the function returns. Memory from malloc or new is on the heap until it is freed.

    This topic is named in a candidate’s interview report: Aruba and R&D intern on-campus interview, 2021, on GeeksforGeeks.

  2. C and C++Medium

    What does this print?

    #include <iostream>
    
    struct A { A() { std::cout << "A "; } ~A() { std::cout << "~A "; } };
    struct B { B() { std::cout << "B "; } ~B() { std::cout << "~B "; } };
    struct C : public B, public A {
        C() { std::cout << "C "; }
        ~C() { std::cout << "~C "; }
    };
    
    int main() {
        C c;
    }
    1. A B C ~C ~B ~A
    2. B A C ~B ~A ~C
    3. C B A ~A ~B ~C
    4. B A C ~C ~A ~B
    Show the answer

    D. B A C ~C ~A ~B

    Base classes are built in the order they are listed in the class declaration (B, then A), whatever order an initialiser list names them in, and then the class itself. Destruction runs in exactly the reverse order.

    This topic is named in a candidate’s interview report: Software development and QA on-campus interview, 2022, on GeeksforGeeks.

  3. C and C++Medium

    In C, which of these declarations is an error?

    1. void *p;
    2. int *q = (int *)p;
    3. void f(void);
    4. void x;
    Show the answer

    D. void x;

    void is an incomplete type with no size, so no variable can have it. A void * is fine: a generic pointer that can hold any object's address, but it must be cast to a real type before you dereference it or do pointer arithmetic.

    This topic is named in a candidate’s interview report: Aruba and R&D intern on-campus interview, 2021, on GeeksforGeeks.

  4. C and C++Medium

    On a typical 64-bit machine with a 4-byte int, what does this print?

    #include <stdio.h>
    
    struct S { int i; char c[8]; };
    union U { int i; char c[8]; };
    
    int main(void) {
        printf("%zu %zu\n", sizeof(struct S), sizeof(union U));
        return 0;
    }
    1. 12 12
    2. 12 8
    3. 8 8
    4. 16 8
    Show the answer

    B. 12 8

    A struct gives every member its own space, 4 + 8 = 12, and 12 is already a multiple of int's 4-byte alignment. A union lays all members over the same bytes, so it is as big as its largest member, 8. Writing u.i and then reading u.c reinterprets those same bytes.

    This topic is named in a candidate’s interview report: R&D intern on-campus interview, 2020, on GeeksforGeeks.

Operating systems 2

  1. Operating systemsEasy

    What is the key difference between two processes and two threads of one process?

    1. Processes have separate address spaces; threads of one process share memory
    2. Threads cannot run at the same time
    3. Processes share memory; threads do not
    4. Threads each need their own copy of the program code
    Show the answer

    A. Processes have separate address spaces; threads of one process share memory

    Threads share the process's heap, globals and open files, so they communicate cheaply but need locks. Processes are isolated, so one crashing does not take the other down, and they talk through pipes, sockets or shared memory.

    This topic is named in a candidate’s interview report: R&D intern on-campus interview, 2020, on GeeksforGeeks.

  2. Operating systemsMedium

    How does a mutex differ from a counting semaphore?

    1. A mutex lets one holder in at a time and is released by its owner; a semaphore allows up to N and anyone may signal it
    2. They are two names for the same thing
    3. A semaphore can only be used between processes
    4. A mutex lets N threads in at once
    Show the answer

    A. A mutex lets one holder in at a time and is released by its owner; a semaphore allows up to N and anyone may signal it

    A mutex is for mutual exclusion over one resource, owned by the thread that locked it. A counting semaphore counts available slots, such as 5 database connections, and is also used for signalling between threads.

    This topic is named in a candidate’s interview report: Aruba and R&D intern on-campus interview, 2021, on GeeksforGeeks.

Computer networks 2

  1. Computer networksEasy

    At which OSI layer does IP routing happen?

    1. Data link (2)
    2. Network (3)
    3. Transport (4)
    4. Application (7)
    Show the answer

    B. Network (3)

    Routers read IP addresses and forward packets between networks at layer 3. Switches work at layer 2 with MAC addresses.

    This topic is named in a candidate’s interview report: Aruba and R&D intern on-campus interview, 2021, on GeeksforGeeks.

  2. Computer networksEasy

    At which layers of the OSI model does a network interface card (NIC) work?

    1. The physical and data link layers: it sends the signal and frames data with its MAC address
    2. Only the application layer
    3. The transport layer
    4. The network layer only
    Show the answer

    A. The physical and data link layers: it sends the signal and frames data with its MAC address

    The NIC turns frames into signals on the wire or radio and back, and its burned-in MAC address is the layer 2 identity a switch learns. IP addresses (layer 3) are set by the operating system, not the card.

    This topic is named in a candidate’s interview report: Aruba and R&D intern on-campus interview, 2021, on GeeksforGeeks.

Aptitude 1

  1. AptitudeMedium

    Nine balls look the same, but one is heavier. With a balance scale, what is the fewest number of weighings that always finds the heavy ball?

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

    C. 2

    Weigh 3 against 3. If they balance, the heavy ball is in the other 3; otherwise it is in the heavier group. Then weigh 1 against 1 from that group the same way. Each weighing has 3 outcomes, and 3 x 3 = 9.

    This topic is named in a candidate’s interview report: R&D intern on-campus interview, 2020, on GeeksforGeeks.

Prep for other employers

All employers
See who is hiring after HPE

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