Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A magical grid of n rows and m columns contains integers from 0 to k 1. Each element in the grid goes through the following

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
A magical grid of n rows and m columns contains integers from 0 to k 1. Each element in the grid goes through the following transformation after each unit of time. grid [i] [j] becomes (grid[i] [j]+1 ) \% k after each unit of time. You are given a 2D array of q queries in the format [t, val, Lx,ly,rx,ry]. Each query contains - t (time) - val (value) - Ix, ly (coordinates of top left corner of subgrid) - rx, ry (coordinates of bottom right corner of subgrid) For each query, find the number of elements in the given subgrid at time t that have the value val. Return an array with the answer to each query. Note: The grid starts at time t=0 and the indices are 0 -based. All Problems K Transformation Accuracy: 66.67% Submissions: 6 Points: 35 Example 1: Input : n=2,m=2k=3grid={{0,1},{2,2}}q=1queries={{1,0,0,0,1,1}} Output: {2} Explanation: Given query can be interpreted as t (time )=1 - val (value) =0 - lx, ly (coordinates of top left corner of subgrid) =(,) - rx,ry (coordinates of bottom right corner of subgrid) =(1,1) Here, the subgrid is the given grid itself. All Problems K Transformation Accuracy: 66.67% Submissions: 6 Points: 35 Output: {2} Explanation: Given query can be interpreted as t (time) =1 - val (value) =0 - lx, ly (coordinates of top left corner of subgrid) =(,) - rx, ry (coordinates of bottom right corner of subgrid) =(1,1) Here, the subgrid is the given grid itself. The count of s at time =1 in the given subgrid is 2 . Your Task: You don't need to read input or print anything. Your task is to complete the function k_Transformation() which takes an integers n,m,k, a 2D array grid, an integer q, and a 2D array queries as input parameters. It returns an array of length q where ith elements correspond to the answer of ith query. Constraints: 1n,m6001k50grid[i][j],val

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions