Drawing Edge
Reported by candidates from WeRide's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
WeRide reportedly sent this one in August 2026, and it looks like a graph problem until you read the constraints. Count the labeled simple undirected graphs on n nodes, return the answer mod 10^9 + 7. The catch is n goes up to 10^9, so you can't build anything, enumerate anything, or loop over pairs. It's a counting problem wearing a graph costume. If you blank on the setup, StealthCoder runs invisibly on your screen during the live OA and gives you the solution as a safety net. You probably won't need it once you see the one-line formula.
The problem
Given n labeled nodes, count the distinct simple undirected graphs that can be drawn on them. For every unordered pair of distinct nodes, an edge may be present or absent. A node cannot have an edge to itself. The graph does not have to be connected. Two graphs are distinct if at least one unordered pair has a different edge state. Return the number of distinct graphs modulo 10^9 + 7. Function drawingEdge(n: int) → int Examples Example 1 n = 3 return = 8 There are three possible undirected edges. Each one can independently be present or absent, so there are 2^3 = 8 distinct graphs. Example 2 n = 4 return = 64 Four nodes have six unordered pairs, so the number of graphs is 2^6 = 64. Constraints 1 <= n <= 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: every unordered pair of distinct nodes is an independent yes/no choice. Pairs number n*(n-1)/2, so the answer is 2^(n(n-1)/2) mod 1e9+7. With n up to 10^9, that exponent is around 5*10^17, so you can't loop. You need fast modular exponentiation, which is O(log exponent). Pitfalls: compute n*(n-1)/2 as a 64-bit integer first (it fits in Python natively, but in Java or C++ use long). Don't reduce the exponent mod 1e9+7. If you want to reduce it, use mod (1e9+6) by Fermat, since 2 and the modulus are coprime. Check the examples: n=3 gives 3 pairs, 8 graphs. n=4 gives 6 pairs, 64 graphs. n=1 gives exponent 0, answer 1. If you freeze on the exponent overflow or the pow call, StealthCoder is the hedge on the live OA.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Drawing Edge cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass WeRide's OA.
WeRide reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Drawing Edge FAQ
What's the trick in the WeRide Drawing Edge problem?+
Each unordered pair of nodes is an independent choice: edge or no edge. There are n(n-1)/2 pairs, so the answer is 2 raised to that power, modulo 10^9 + 7. Connectivity doesn't matter, and self-loops are banned, so nothing else adjusts the count.
Why can't I brute force this with n up to 10^9?+
Even the number of pairs is about 5*10^17, so you can't iterate over edges, let alone graphs. You need a closed-form formula and fast modular exponentiation that runs in logarithmic time in the exponent.
Do I need to reduce the exponent modulo something?+
Not required. Use built-in pow(2, e, MOD) in Python, or write binary exponentiation with a 64-bit exponent. If you want to shrink it, reduce mod 10^9+6 by Fermat's little theorem, since the modulus is prime and 2 isn't a multiple of it.
What edge cases should I test?+
Test n=1, which has zero pairs and returns 1. Then n=2, which returns 2. Then the given examples, 3 giving 8 and 4 giving 64. Finally test n=10^9 for overflow: compute n*(n-1)/2 in 64-bit before exponentiating.
How do I prepare for this in 48 hours?+
Practice writing modular exponentiation from memory, then drill the habit of spotting independent binary choices in counting problems. Run the two examples by hand. This one is a ten-line solution once you see it, so the prep is recognition, not heavy algorithms.