Two Sigma OA 2024 sde – 一亩三分地 – OA代写 – 面试代面 – 代面试

Two Sigma OA 2024 sde 平台hackrank,限时180分钟3道题,我们一起来看看其中2道题吧。

Two Sigma OA 2024 sde platform hackrank, with a time limit of 180 minutes and 3 questions, let’s take a look at 2 of them.

1. Pythagorean Triples

There is a tree with tree_nodes nodes where the nodes are numbered from 0 to tree_nodes - 1. The distance between two nodes 𝑥x and 𝑦y, distance(x, y) = the number of edges in the unique path from node 𝑥x to node 𝑦y.

A Pythagorean triple (𝑎,𝑏,𝑐)(a,b,c) is one where 𝑎2+𝑏2=𝑐2a2+b2=c2. For three nodes 𝑥,𝑦,x,y, and 𝑧z, node 𝑖i is called special if its distances to the three nodes, sorted ascending form a Pythagorean triple.

Example:

tree_nodes = 10
tree_edges = 9
tree_from = [0, 0, 1, 3, 3, 5, 7, 8]
tree_to = [4, 1, 2, 5, 7, 6, 8, 9]

x = 4, y = 6, and z = 9

Each tree_from[i] is connected to tree_to[i] with a bidirectional edge. Here, only node 2 forms the Pythagorean triple. Its distance from 𝑥x, node 4, is 3, from 𝑦y, node 6, is 4, and from 𝑧z, node 9, is 5. (3,4,5)(3,4,5) is a Pythagorean triple. The answer is 1.

Function Description

Complete the function countPythagoreanTriples in the editor below.

countPythagoreanTriples has the following parameters:

  • int tree_nodes: the number of nodes
  • int tree_from[n]: one end of edge 𝑖i
  • int tree_to[n]: the other end of edge 𝑖i
  • int x: the node associated with value 𝑎a in the Pythagorean triple
  • int y: the node for value 𝑏b
  • int z: the node for value 𝑐c

Returns

int: the total number of special nodes

Sample Input For Custom Testing

STDIN

9 8  -> tree_nodes = 9, tree_edges = tree_nodes - 1 = 8
0 1 -> tree_from = [0, 1, 2, 3, 4, 5, 6, 7], tree_to = [1, 2, 3, 4, 5, 6, 7, 8]
1 2
2 3
3 4
4 5
5 6
6 7
7 8
3 -> x = 3
4 -> y = 4
5 -> z = 5

Sample Output

2

Explanation

Here,

  • tree_nodes = 9
  • tree_edges = 8
  • tree_from = [0, 1, 2, 3, 4, 5, 6, 7]
  • tree_to = [1, 2, 3, 4, 5, 6, 7, 8]
  • x = 3
  • y = 4
  • z = 5

2. Binary Operations

Given a positive integer 𝑛n, in a single operation, choose any 𝑖≥0i≥0 and convert 𝑛n to 𝑛+2𝑖n+2i or 𝑛−2𝑖n−2i.

Find the minimum number of operations required to convert 𝑛n to 0.

Example

n = 5

𝑛n can be reduced to 0 using two operations.

5 -> 5 - 2^0 = 4 -> 4 - 2^2 = 0
  • Choose 𝑖=0i=0, and subtract 2020 from 5, 5−1=45−1=4.
  • Choose 𝑖=2i=2, and subtract 2222 from 4, 4−4=04−4=0.

The answer is 2. It can be shown that answer cannot be less than 2.

Function Description

Complete the function getMinOperations in the editor below.

getMinOperations has the following parameter:

  • int n: the number to reduce

Returns

  • int: the minimum number of operations required

Constraints

  • 1≤𝑛<2601≤n<260

Input Format For Custom Testing

Sample Case 0

Sample Input For Custom Testing

STDIN      Function
21 -> n = 21

Sample Output

3

Explanation

21 -> 21 - 2^0 = 20 -> 20 - 2^2 = 16 -> 16 - 2^4 = 0

我们提供OA代写服务,代面试服务,面试辅助服务等。对于OA代写我们将确保你获得满分,联系我们立即进行预约。

We provide services for writing online assessments (OA), proxy interviews, and interview assistance. For the OA writing service, we will ensure that you achieve a perfect score. Contact us now to make an appointment.

Leave a Reply

Your email address will not be published. Required fields are marked *