Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Solve Rotten Oranges Array

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Solve Rotten Oranges Array. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

In an Okta Workforce Identity Cloud access pipeline, a compromised session spreads to adjacent sessions over time. Given a grid, compute how many minutes are required for all fresh sessions to become compromised. Also analyze an activity array by finding the longest contiguous subarray containing at most k distinct values.

Implement solve_access_analysis(grid, nums, k) and return [minutes, longest_length].

For the grid, 0 represents an empty cell, 1 represents a fresh session, and 2 represents an initially compromised session. Each minute, every compromised cell changes its up, down, left, or right fresh neighbors to compromised. Return -1 if at least one fresh session can never be reached.

For the array, return the maximum length of a contiguous subarray containing no more than k distinct values. Return 0 when k is zero or the array is empty.

Formal Specification

  • grid is a rectangular list of lists of integers and may be empty.
  • nums is a list of integers.
  • k is a nonnegative integer.
  • Return a two-element list [minutes, longest_length].

Constraints

  • 0 <= rows, cols <= 100
  • 0 <= len(nums) <= 10^5
  • grid[i][j] is one of 0, 1, or 2
  • 0 <= k <= len(nums)
  • The grid is rectangular when it is nonempty

Function Signature

def solve_access_analysis(grid, nums, k):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output