7 kyu

Normalize the jagged array

Description:

Description

An array of arrays is referred to as jagged if its subarrays have varying lengths. However, in certain scenarios, you might need to normalize a jagged array. Normalizing, in this context, involves transforming it into a rectangular matrix of dimensions N x M, where N represents the number of subarrays and M represents the length of the longest subarray. This transformation is achieved by padding shorter subarrays with a specified value (passed as an argument) until they match the length of the longest subarray.

# normalizing the array with value None (python example)

[
[1, 2, 3],
[4],
[5, 6, 7, 8]
]

will turn into:

[
[1, 2, 3, None],
[4, None, None, None],
[5, 6, 7, 8]
]

Your task

Implement a function that accepts a jagged array as input and returns its normalized version.

Notes

  • All inputs are valid jagged arrays containing N subarrays, where 0 ≤ N ≤ 15, with integers ranging from 0 to 9.
  • The fill value for padding can vary and will be specified in the function's signature.
  • There are 100 random tests.
Arrays

More By Author:

Check out these other kata created by оkabe

Stats:

CreatedSep 20, 2022
PublishedSep 20, 2022
Warriors Trained327
Total Skips2
Total Code Submissions496
Total Times Completed256
Python Completions256
Total Stars1
% of votes with a positive feedback rating93% of 119
Total "Very Satisfied" Votes105
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes2
Total Rank Assessments101
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • оkabe Avatar
  • heroicfun Avatar
  • KayleighWasTaken Avatar
Ad