FastPrepDrawing Edge

Drawing Edge

WeRide logoWeRideâ—Ź EasyFULLTIMEOA

Problem statement

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 = 3return = 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 = 4return = 64

Four nodes have six unordered pairs, so the number of graphs is 2^6 = 64.

Constraints

  • 1 <= n <= 10^9

More WeRide problems

See WeRide hiring insights
Saved
public int drawingEdge(int n) {
    // Write your code here
}
n3
expected8
Checking account…