InternDoor

Societe Generale interview prep

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

Practise them as a timed round10 roles open at Societe Generale Global Solution Centre

DSA 4

  1. DSAMedium

    You reverse a singly linked list in place by walking it once with three pointers, prev, curr and next. At each node, what do you do?

    1. Save next = curr.next, point curr.next at prev, then move prev to curr and curr to next
    2. Swap the node's value with the value at the other end of the list
    3. Push every node onto a stack, then pop them all
    4. Point curr.next at curr.next.next
    Show the answer

    A. Save next = curr.next, point curr.next at prev, then move prev to curr and curr to next

    Saving next first keeps the rest of the list reachable after the link is turned round. When curr becomes null, prev is the new head. One pass, O(n) time, O(1) extra space.

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

  2. DSAMedium

    In this grid, 1 is land and 0 is water, and land joins up, down, left and right. How many islands are there?

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

    C. 4

    The top-left 1s form one island; the two 1s in the right column form another; the lone 1 at row 3, column 1 and the lone 1 at row 4, column 3 are one each: 4. A DFS from each unvisited land cell is O(rows x columns).

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

  3. DSAMedium

    You build a stack from two queues. push(x) enqueues x into the empty queue q2, moves every element of q1 behind it, then swaps the names of q1 and q2. What do push and pop cost?

    1. O(n) push and O(1) pop
    2. O(1) and O(1)
    3. O(1) push and O(n) pop
    4. O(log n) each
    Show the answer

    A. O(n) push and O(1) pop

    Moving q1's n elements behind the new one leaves the newest at the front of q1, so pop is a single dequeue. The other design makes push a plain enqueue and pop O(n), moving n - 1 elements across to reach the last one.

    This topic is named in a candidate’s interview report: Intern and full-time on-campus interview, 2022, on GeeksforGeeks.

  4. DSAHard

    What is the best known time to find the median of two sorted arrays of sizes m and n?

    1. O(m + n), by merging
    2. O((m + n) log(m + n)), by sorting
    3. O(log(min(m, n))), by binary searching the cut in the smaller array
    4. O(m * n)
    Show the answer

    C. O(log(min(m, n))), by binary searching the cut in the smaller array

    Cut the smaller array at i and the larger at (m + n + 1) / 2 - i so the left halves together hold half the elements, then binary search i until every left value is at most every right value. Merging to the middle is the simpler O(m + n) answer.

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

Java 1

  1. JavaHard

    What does this print?

    public class Main {
        public static void main(String[] args) {
            Integer a = 127, b = 127;
            Integer c = 128, d = 128;
            int e = 128;
            System.out.println((a == b) + " " + (c == d) + " " + (c == e));
        }
    }
    1. true true true
    2. true false false
    3. false false true
    4. true false true
    Show the answer

    D. true false true

    Autoboxing calls Integer.valueOf, which returns cached objects for -128 to 127, so a and b are the same object. 128 is outside the cache, so c and d are two objects and == compares references. c == e unboxes c to an int and compares values. Use equals for Integer objects.

    This topic is named in a candidate’s interview report: Global Solutions Centre on-campus interview, 2020, on GeeksforGeeks.

Python 1

  1. PythonEasy

    What does this print?

    def down(n):
        if n == 0:
            return
        print(n, end=" ")
        down(n - 1)
    
    def up(n):
        if n == 0:
            return
        up(n - 1)
        print(n, end=" ")
    
    down(3)
    print("|", end=" ")
    up(3)
    1. 3 2 1 | 3 2 1
    2. 1 2 3 | 1 2 3
    3. 1 2 3 | 3 2 1
    4. 3 2 1 | 1 2 3
    Show the answer

    D. 3 2 1 | 1 2 3

    down prints before it recurses, so 3 comes out first. up recurses all the way to 0 first and prints as each call returns, so the deepest call, n = 1, prints first. The same function body gives either order depending on where the print sits.

    This topic is named in a candidate’s interview report: Global Solutions Centre on-campus interview, 2020, on GeeksforGeeks.

C and C++ 5

  1. C and C++Hard

    Why should a base class that is used polymorphically have a virtual destructor?

    1. Deleting a derived object through a base pointer is otherwise undefined behaviour, and the derived destructor usually never runs
    2. Without it, the class cannot be instantiated
    3. It makes destruction faster
    4. Virtual destructors are needed for any class that has a constructor
    Show the answer

    A. Deleting a derived object through a base pointer is otherwise undefined behaviour, and the derived destructor usually never runs

    delete on a Base* that points at a Derived uses the static type unless the destructor is virtual. Then the Derived part is never cleaned up (the standard calls it undefined behaviour), which leaks resources.

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

  2. C and C++Medium

    You wrote an integer stack class in C++ and now need the same stack for strings and doubles. What is the idiomatic change?

    1. Copy the class once for each type
    2. Make it a class template, template <typename T> class Stack, storing T values
    3. Store everything as void* and cast
    4. Use a macro to rename int
    Show the answer

    B. Make it a class template, template <typename T> class Stack, storing T values

    A template generates a type-safe class for each T used, such as Stack<std::string>, with no casts. std::stack is exactly this, built over a container like std::deque.

    This topic is named in a candidate’s interview report: SDE on-campus interview, Bangalore, 2023, on LeetCode.

  3. C and C++Medium

    What does this print?

    #include <iostream>
    #include <stdexcept>
    #include <vector>
    
    class IntStack {
        std::vector<int> v;
    public:
        void push(int x) { v.push_back(x); }
        int pop() {
            if (v.empty()) throw std::underflow_error("empty");
            int x = v.back();
            v.pop_back();
            return x;
        }
    };
    
    int main() {
        IntStack s;
        s.push(7);
        try {
            std::cout << s.pop() << " ";
            std::cout << s.pop() << " ";
        } catch (const std::underflow_error& e) {
            std::cout << e.what();
        }
    }
    1. 7 0
    2. 7 empty
    3. 7 7
    4. empty
    Show the answer

    B. 7 empty

    The first pop returns 7. The second finds the stack empty and throws before printing anything, so control jumps to the catch block, which prints the exception's message.

    This topic is named in a candidate’s interview report: SDE on-campus interview, Bangalore, 2023, on LeetCode.

  4. C and C++Medium

    A C++ function throws an exception and no catch block anywhere up the call stack matches its type. What happens?

    1. std::terminate is called, which by default aborts the program
    2. The exception is ignored and the program continues
    3. The compiler refuses to build the program
    4. The function returns 0
    Show the answer

    A. std::terminate is called, which by default aborts the program

    throw unwinds the stack, running destructors, until a matching catch is found. With none, std::terminate runs. catch (...) catches anything, and catching by const reference (catch (const std::exception& e)) avoids slicing a derived exception.

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

  5. C and C++Medium

    What does this print?

    #include <iostream>
    
    struct Tag {
        char c;
        Tag(char x) : c(x) { std::cout << c << "+ "; }
        ~Tag() { std::cout << c << "- "; }
    };
    
    int main() {
        Tag a('A');
        {
            Tag b('B');
        }
        Tag c('C');
    }
    1. A+ B+ C+ A- B- C-
    2. A+ B+ C+ C- B- A-
    3. A+ B+ B- C+ C- A-
    4. A+ B+ B- C+ A- C-
    Show the answer

    C. A+ B+ B- C+ C- A-

    A local object is destroyed when its scope ends, so b dies at the inner closing brace, before c is built. At the end of main, objects are destroyed in reverse order of construction: c before a.

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

DBMS and SQL 2

  1. DBMS and SQLMedium

    Which query returns the second-highest salary in emp?

    1. SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp);
    2. SELECT salary FROM emp ORDER BY salary LIMIT 2;
    3. SELECT MAX(salary) - 1 FROM emp;
    4. SELECT SECOND(salary) FROM emp;
    Show the answer

    A. SELECT MAX(salary) FROM emp WHERE salary < (SELECT MAX(salary) FROM emp);

    The subquery finds the top salary, and the outer MAX finds the largest one below it. It also handles ties at the top correctly.

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

  2. DBMS and SQLMedium

    Inside one transaction you insert row A, run SAVEPOINT s1, insert row B, then run ROLLBACK TO SAVEPOINT s1 and COMMIT. Which rows are saved?

    1. Neither A nor B
    2. Only B
    3. Only A
    4. Both A and B
    Show the answer

    C. Only A

    ROLLBACK TO a savepoint undoes only the work done after it, so B is discarded while the transaction stays open, and COMMIT then saves A. A plain ROLLBACK would have undone everything since the transaction began.

    This topic is named in a candidate’s interview report: SDE on-campus interview, Bangalore, 2023, on LeetCode.

Web development 1

  1. Web developmentEasy

    After a release, some users say a page shows two of its three new buttons, while it looks right for you. What is the most likely cause?

    1. The server is down for those users
    2. Their screens are too small
    3. Their browser or a CDN is serving the old cached JavaScript or CSS next to the new HTML; versioned asset URLs (app.js?v=2 or a content hash) prevent it
    4. The database lost the third button
    Show the answer

    C. Their browser or a CDN is serving the old cached JavaScript or CSS next to the new HTML; versioned asset URLs (app.js?v=2 or a content hash) prevent it

    HTML is often revalidated on every load while scripts and stylesheets are cached for minutes or days, so a user can get new markup with an old script. A hard refresh fixes it for one user; a new URL per release fixes it for everyone.

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

Aptitude 1

  1. AptitudeMedium

    "The day before yesterday I was 21, and next year I will turn 24." On which day can this be true?

    1. Only on 1 January, for someone born on 31 December
    2. Only on a birthday
    3. Only in a leap year
    4. It can never be true
    Show the answer

    A. Only on 1 January, for someone born on 31 December

    Said on 1 January: on 30 December they were 21, on 31 December they turned 22, on 31 December this year they turn 23, and on 31 December next year 24. Any other date leaves no room for two birthdays between now and the end of next year.

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

Prep for other employers

All employers
See who is hiring after Societe Generale

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