Cube of Matrix Problem Statement

Given a 2D array 'MATRIX' of size M x N, find and return the value (i * i + j * j) for those elements where the sum of the cubes of its digits equals the element itself. Here, 'i' is the row index ranging from 0 to M-1, and 'j' is the column index ranging from 0 to N-1.

Note:

If no such element exists, return -1.

Input:

The first line contains an integer ‘T’ which represents the number of test cases. Each test case consists of two lines:
The first line contains two integers ‘M’ and ‘N’ indicating the number of rows and columns, respectively.
The second line contains ‘M’ * ’N’ space-separated integers, representing the elements of the 2D array 'MATRIX'.

Output:

For each test case, output the (i * i + j * j) value for elements where the sum of the cube of its digits equals the element itself.
Note:
You are not required to print the output, it is already handled. Just implement the function.

Constraints:

  • 1 <= T <= 10
  • 1 <= M <= 100
  • 1 <= N <= 50
  • 1 <= ELEMENT <= 109
  • Time limit: 1 second
AnswerBot
6d

Given a 2D array, find elements where sum of cube of digits equals element itself and return (i * i + j * j) value.

  • Iterate through the 2D array and check if the sum of cube of digits equals the elemen...read more

Help your peers!
Add answer anonymously...
Societe Generale Global Solution Centre Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter