dd.metro
BAN USER- -2of 2 votes
AnswersGiven an array of numbers print the values in diagonal format.
- dd.metro in United States
Example (1) for 8 dataset
Input Array : [1, 2, 3,4,5,6,7,8]
Output
01 02 04 07
03 05 08
06
Example (2) for 45 dataset
Input Array: [1, 2, 3,4,5,6,7,8,9,10……….44, 45]
Output
01 02 04 07 11 15 19 23 27 31 35 39
03 05 08 12 16 20 24 28 32 36 40 43
06 09 13 17 21 25 29 33 37 41 44
10 14 18 22 26 30 34 38 42 45
Code in Java.| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer
- 0 Answers Question to all you nerds
Question to all you nerds : -
- dd.metro October 30, 2014
(Not an interview question)
Need a math formula to determine a result number based on provided input (Row number: a, Column number: b, Total Rows: p, Total column: q). let me explain the scenario :
Scenario 1:
01 02 06 07 14 15 22 23 30 31 38 39
03 05 08 13 16 21 24 29 32 37 40 45
04 09 12 17 20 25 28 33 36 41 44 46
10 11 18 19 26 27 34 35 42 43 47
For the above given matrix. If you notice numbers are ordered diagonally down and then diagonally upwards.
If Row number is given as 1 and column 1 for total rows 4 and column 12 I should get value 1
If Row number is given as 2 and column 3 for total rows 4 and column 12 I should get value 8
If Row number is given as 3 and column 12 for total rows 4 and column 12 I should get value 46
Formula should be generic to derive any number provided row and col.
Scenario 2:
Similar to above if number of rows increases from 4-5 still the formula should be able to derive the number correctly provide those row/col/total row and total columns.
01 02 06 07 15 16 25 26 35
03 05 08 14 17 24 27 34
04 09 13 18 23 28 33
10 12 19 22 29 32
11 20 21 30 31
Please help. Thanks in advance| Flag | PURGE
I liked this solution but it does not solve the problem..
- dd.metro October 26, 2014This solution increases the row count as given in problem statement also does not reduce the inc counter at the End.
If you notice increment counter should reduce from 4 to 3 at the end. for example after 40 it expected to print 43 not 44.
Number of rows (4 in this example) should also be an input, number of column should be calculated (12 in this example).