×

# BOND - Editorial

Author: Nishchith Shetty

Tester: Neel Shah

Editorialist: Rushang Gajjal

EASY

# PREREQUISITES:

implemenatation, observation

# PROBLEM:

Given a number X , take each digit in turn from left to right . For each digit follow that many black arrows in a row and then follow one white arrow , initial position being point A . We have to find the node on which BOND will land after performing the given operations on X.

# EXPLANATION:

We can Solve this problem in two ways : 1. straight off Implementation and 2. Observation.

### Method 1: Implementation

Each element is the list [A,B,C,D,E,F,G] is denoted by its index i ranging from 0 to 6. So A -> 0, B -> 1 and so on. For each node let's store the next node it will reach if we follow the black arrow or the white arrow respectively.

l = [[1, 0], [3, 2], [4, 3], [2, 5], [6, 6], [0, 4], [5, 1]]

i.e. A -> l[0] = [1,0] -> [ B , A ]. From A if we move along black arrow we reach B or if we move along white arrow we reach A.

Starting from A i.e 0 (start = 0), Now for each digit n in the integer X we perform n moves along black arrow and then move along a white arrow. We can do this by

for i in range(n): start = l[start][0] #move along black arrow start = l[start][1] #move along white arrow

Value of start is initially 0. After the above operations we just print the element denoted by the start variable.

• Time Complexity: O(|X|)

### Method 2: Observation

Similarly if we perform X moves along black arrows and then a move along white arrow we can notice that each node can be represented by the value obtained by X mod 7.

A -> (X mod 7 = 0)

C -> (X mod 7 = 1)

F -> (X mod 7 = 2)

D -> (X mod 7 = 3)

G -> (X mod 7 = 4)

B -> (X mod 7 = 5)

E -> (X mod 7 = 6)

• Time Complexity: O(1)

# AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here

Tester's solution can be found here

This question is marked "community wiki".

4★rusherrg
13
accept rate: 0%

19.7k350498541

 1 James bond 007 . It was really clever hint for this problem. @inishchith Really nice ! I liked idea ! It was really hilarious ! answered 01 Oct '18, 01:14 5★cis_pie 105●5 accept rate: 9%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×3,741
×825
×342
×228
×35

question asked: 01 Oct '18, 01:06

question was seen: 619 times

last updated: 30 Oct '18, 20:24