CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!) D. Ones and Twos
3119. Maximum Number of Potholes That Can Be Fixed
You are given a string
road
, consisting only of characters"x"
and"."
, where each"x"
denotes a pothole and each"."
denotes a smooth road, and an integerbudget
.In one repair operation, you can repair
n
consecutive potholes for a price ofn + 1
.Return the maximum number of potholes that can be fixed such that the sum of the prices of all of the fixes doesn’t go over the given budget.
3109. Find the Index of Permutation
Given an array
perm
of lengthn
which is a permutation of[1, 2, ..., n]
, return the index ofperm
in the lexicographically sorted array of all of the permutations of[1, 2, ..., n]
.Since the answer may be very large, return it modulo
109 + 7
.
You are given
row x col
grid
representing a map wheregrid[i][j] = 1
represents land andgrid[i][j] = 0
represents water.
grid
is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).The island doesn’t have “lakes”, meaning the water inside isn’t connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don’t exceed 100. Determine the perimeter of the island.