title-img


Poisonous Plants

There are a number of plants in a garden. Each of the plants has been treated with some amount of pesticide. After each day, if any plant has more pesticide than the plant on its left, being weaker than the left one, it dies. You are given the initial values of the pesticide in each of the plants. Determine the number of days after which no plant dies, i.e. the time after which there is no plant with more pesticide content than the plant to its left. Example p = [ 3, 6, 2, 7, 5 ] // pe

View Solution →

Roads and Libraries

Determine the minimum cost to provide library access to all citizens of HackerLand. There are n cities numbered from 1 to n. Currently there are no libraries and the cities are not connected. Bidirectional roads may be built between any city pair listed in cities. A citizen has access to a library if: 1. Their city contains a library. 2. They can travel by road from their city to a city containing a library. unction Description Complete the function roadsAndLibraries in the editor be

View Solution →

Find the nearest clone

In this challenge, there is a connected undirected graph where each of the nodes is a color. Given a color, find the shortest path connecting any two nodes of that color. Each edge has a weight of . If there is not a pair or if the color is not found, print -1. Function Description Complete the findShortest function in the editor below. It should return an integer representing the length of the shortest path between two nodes of the same color, or -1 if it is not possible. findShorte

View Solution →

BFS: Shortest Reach in a Graph

Consider an undirected graph consisting of n nodes where each node is labeled from 1 to n and the edge between any two nodes is always of length 6. We define node s to be the starting position for a BFS. Given a graph, determine the distances from the start node to each of its descendants and return the list in node number order, ascending. If a node is disconnected, it's distance should be -1. For example, there are n = 6 nodes in the graph with a starting node s = 1 . The list of edges =

View Solution →

DFS: Connected Cell in a Grid

Consider a matrix where each cell contains either a 0 or a 1 and any cell containing a 1 is called a filled cell. Two cells are said to be connected if they are adjacent to each other horizontally, vertically, or diagonally. In the diagram below, the two colored regions show cells connected to the filled cells. Black on white are not connected. If one or more filled cells are also connected, they form a region. Note that each cell in a region is connected to at least one other cell in the r

View Solution →