Algorithm · Netflix · Easy
You are given an integer array arr. Your task is to produce its one-hot encoded representation as a 2D array (matrix). In this encoding: Each row corresponds to one element of arr. Each column represents one of the distinct values that appear in arr, arranged in ascending order. For the element at index i, the cell at row i and the column matching arr[i] is set to 1; all other cells in that row are 0. In other words, the number of columns equals the number of distinct values…
Checking your access…