Skip to content

Instantly share code, notes, and snippets.

@HofmannZ
Last active April 22, 2024 13:59
Show Gist options
  • Save HofmannZ/80a55edffbdc78b89a864ffb82016e85 to your computer and use it in GitHub Desktop.
Save HofmannZ/80a55edffbdc78b89a864ffb82016e85 to your computer and use it in GitHub Desktop.

Senior Back-End Engineer Technical Interview

Introduction

During this 45-minute video call, you will be asked to complete three coding exercises. You're encouraged to discuss your thought process, the trade-offs you consider, and the complexity of your solutions. We are using TypeScript and Node.js for our stack, so please ensure your solutions are compatible with these technologies.

Exercise 1: Advanced Sorting

Problem Statement

Given an array of n objects, each with properties id (a unique integer) and timestamp (a JavaScript Date object), write a function to sort the array. The primary sort key should be timestamp (oldest to newest), and the secondary key (in case of ties) should be id (smallest to largest).

Requirements

  • Implement a sorting function that efficiently handles the specified criteria.
  • Discuss the time complexity (Big O notation) of your solution and any performance implications.

Example Input

[
  { id: 3, timestamp: new Date('2024-01-01T15:00:00') },
  { id: 1, timestamp: new Date('2024-01-01T12:00:00') },
  { id: 2, timestamp: new Date('2024-01-01T12:00:00') }
]

Example Output

[
  { id: 1, timestamp: new Date('2024-01-01T12:00:00') },
  { id: 2, timestamp: new Date('2024-01-01T12:00:00') },
  { id: 3, timestamp: new Date('2024-01-01T15:00:00') }
]

Exercise 2: Graph Traversal

Problem Statement

Given a directed graph represented as an adjacency list, write a function to perform a breadth-first search (BFS) starting from a given node. Your function should return an array of nodes in the order they were visited.

Requirements

  • Implement the BFS algorithm using appropriate data structures.
  • Discuss the time and space complexity of your solution.

Example Input

const graph = {
  A: ['B', 'C'],
  B: ['D', 'E'],
  C: ['F'],
  D: [],
  E: ['F'],
  F: [],
};
const startNode = 'A';

Example Output

['A', 'B', 'C', 'D', 'E', 'F']

Exercise 3: Memory Leak Detection and Fix

Problem Statement

The following Node.js code is known to cause a memory leak when run over time. Identify the memory leak and refactor the code to fix it.

Initial Code

type Data = {
  info: string;
  time: number;
};

class DataStore {
  data: Data[];

  constructor() {
    this.data = [];
  }

  addData(newData: Data) {
    this.data.push(newData);
  }

  processData() {
    this.data.forEach((dataItem) => {
      // Imagine some complex processing here
    });
  }
}

const store = new DataStore();
setInterval(() => {
  store.addData({ info: 'Sample data', time: Date.now() });
  store.processData();
}, 1000);

Requirements

  • Identify the memory leak in the code.
  • Provide a refactored solution that resolves the memory leak.
  • Discuss how your changes improve the application's memory management.

Conclusion

Throughout the interview, explain your approach, the optimizations you make, and the complexity of each solution. This will help us understand not only your technical skills but also how you approach problem-solving under constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment