FastPrepDrawing Edge

Drawing Edge

IBM logoIBM● EasyFULLTIMEINTERNOA
Learn

Problem statement

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 = 4return = 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 = 2return = 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

More IBM problems

See IBM hiring insights
public int drawingEdge(int n) {
  // Write your code here.
}
n4
expected64
Checking account…