Skip to content
Discussion options

You must be logged in to vote

To solve this problem, we can follow these steps:

  1. Mapping Function: Create a function to convert an integer to its mapped value using the provided mapping array.
  2. Custom Sorting: Use the usort function in PHP to sort the array based on the mapped values.

Let's implement this solution in PHP: 2191. Sort the Jumbled Numbers

<?php
// Example usage:
$mapping = [8,9,4,0,2,1,3,5,7,6];
$nums = [991,338,38];
print_r(sortJumbled($mapping, $nums)); // Output: [338, 38, 991]
?>

Explanation:

  1. mapNumber Function: This function takes a number and the mapping array as input and returns the mapped value of the number. It converts the number to a string, replaces each digit with its mapped value, and the…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
1 participant