Drawing Edge
Reported by candidates from IBM's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The IBM Drawing Edge question, reported in August 2026, looks like a graph problem and isn't one. Strip the vertices and edges away and you're counting subsets. n labeled vertices give n(n-1)/2 possible edges, and each one is either drawn or not. The answer is 2 raised to that count, modulo 10^9 + 7. The catch is that n goes up to 10^9, so you can't loop or brute force anything. If you blank on the exponent handling during the live assessment, StealthCoder runs invisibly on your desktop and gives you the solution as a safety net.
The problem
You are given n labeled vertices. For every unordered pair of distinct vertices, you may either draw one undirected edge between them or leave them disconnected. A graph may be disconnected. Two graphs are different when at least one pair of vertices has a different edge choice. Return the number of distinct simple undirected graphs that can be formed, modulo 10^9 + 7. Complete drawingEdge with the parameter int n and return the result as an int. Function drawingEdge(n: int) → int Examples Example 1 n = 4 return = 64 Four vertices determine 4 * 3 / 2 = 6 possible edges. Each edge can be absent or present independently, so the number of graphs is 2^6 = 64. Example 2 n = 2 return = 2 There is one possible edge between the two vertices. It can be absent or present, so there are 2 graphs. Constraints 1 <= n <= 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is one formula: answer = 2^(n(n-1)/2) mod 1e9+7. Compute the edge count E = n*(n-1)/2 first. With n up to 10^9, E reaches about 5*10^17, which overflows a 32-bit int but fits in a signed 64-bit integer. Python handles it natively, so use long in Java or C++. Then use fast modular exponentiation, which runs in about 60 iterations. Don't compute 2^E and then take the modulus, because that blows up. The common pitfall is reducing the exponent by the modulus directly. You can reduce it mod (p-1) by Fermat's little theorem, but it's unnecessary here since E fits in 64 bits. Another pitfall is overthinking connectivity. The problem explicitly allows disconnected graphs, so there's no inclusion-exclusion. If the formula or the overflow handling slips your mind mid-assessment, StealthCoder can supply the working code from the screen.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass IBM's OA.
IBM reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Drawing Edge FAQ
What's the trick in IBM's Drawing Edge problem?+
It's a counting problem in disguise. Every pair of distinct vertices is an independent yes/no choice, so the total is 2 to the power of n(n-1)/2. Disconnected graphs are allowed, so no connectivity logic is needed. Apply the modulus 10^9 + 7 with fast exponentiation.
How hard is Drawing Edge really?+
Easy once you see the formula, and the examples practically hand it to you: n=4 gives 2^6 = 64 and n=2 gives 2^1 = 2. The difficulty is only in handling the huge n, which means 64-bit arithmetic and modular exponentiation instead of loops.
Why can't I just compute 2^E directly?+
With n up to 10^9, E is around 5*10^17, so 2^E has an astronomically large number of digits. You must use binary exponentiation and take the modulus at every multiplication step. That's about 60 squarings, so it runs instantly.
Do I need to worry about integer overflow?+
Yes, in typed languages. n*(n-1) can reach about 10^18, which fits in a signed 64-bit integer but not in 32 bits. Use long in Java or long long in C++. Python is safe. Also keep multiplications inside the modular power function in 64-bit.
How do I prepare for this in 48 hours?+
Write modular exponentiation from memory and test it on a couple of small inputs. Then solve the examples by hand: n=1 gives 1, n=2 gives 2, n=4 gives 64. Skim other counting-with-modulus problems so the 10^9 + 7 pattern feels routine.