Six Degrees, Give or Take

Hard

· Frontend

Incident

SEV-2

BUG-DEGREES

Priority: High · reported by profile team

Time to fix: 35 min

Failing checks on the shipped build

  • direct connections are first degree

    shortest path, not first found: expected 1 but got 3

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

LinkedIn

Inspired by the "2nd-degree connection" labels of professional networks — which must be the shortest path between two people. Depth-first exploration returns the first path it stumbles into, and profiles show "3rd" for direct connections.

degrees.js computes connection degree. It needs breadth-first, not depth-first.

Code map

// Connection degree between two members.
exports.degree = function (network, from, to) {
  var visited = {};

  function dfs(node, depth) {
    if (node === to) return depth;
    visited[node] = true;
    var neighbors = network[node] || [];
    for (var i = 0; i < neighbors.length; i++) {
      if (!visited[neighbors[i]]) {
        var found = dfs(neighbors[i], depth + 1);
        if (found !== -1) return found;
      }
    }
    return -1;
  }

  return dfs(from, 0);
};

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

Six Degrees, Give or Take — JavaScript Bug Hunt

Inspired by the "2nd-degree connection" labels of professional networks — which must be the shortest path between two people.

  • Language: JavaScript
  • Layer: Frontend
  • Difficulty: Hard
  • Concepts: Graphs, BFS
  • Modelled on: LinkedIn
  • Visible tests: direct connections are first degree; second degree via a mutual; unreachable members are -1, self is 0
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2 (priority: High)
  • Ticket: BUG-DEGREES
  • Reported by: profile team
  • Time to fix: 35 minutes, the target for a hard incident

Failing checks on the shipped build

  • direct connections are first degree — shortest path, not first found: expected 1 but got 3

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Inspired by the "2nd-degree connection" labels of professional networks — which must be the shortest path between two people. Depth-first exploration returns the first path it stumbles into, and profiles show "3rd" for direct connections.

degrees.js computes connection degree. It needs breadth-first, not depth-first.

Bug report

BUG-DEGREES · Priority: High · Reported by: profile team

degree(network, from, to):

  • the SHORTEST connection distance (1 = direct)
  • unreachable -> -1, self -> 0

Observed: alice and dave are directly connected, but because the traversal dives down alice → bob → carol → dave first, the label says 3rd.

Logs

[profile] degree(alice, dave) = 3 (they are 1st-degree!)

The code as shipped

src/graph/degrees.js (editable)

// Connection degree between two members.
exports.degree = function (network, from, to) {
  var visited = {};

  function dfs(node, depth) {
    if (node === to) return depth;
    visited[node] = true;
    var neighbors = network[node] || [];
    for (var i = 0; i < neighbors.length; i++) {
      if (!visited[neighbors[i]]) {
        var found = dfs(neighbors[i], depth + 1);
        if (found !== -1) return found;
      }
    }
    return -1;
  }

  return dfs(from, 0);
};

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.