Two non-negative integers are called siblings if they can be obtained from each other by rearranging the digits of their decimal representations. For example, 123 and 213 are siblings. 535 and 355 are also siblings.
A set consisting of a non-negative integer N and all of its siblings is called the family of N. For example, the family of 553 comprises three numbers: 355, 535 and 553. Write a function that, given a non-negative integer N, returns the largest number in the family of N.
The function should return −1 if the result exceeds 100,000,000. For example, given N = 213 the function should return 321. Given N = 553 the function should return 553. Python or c++ code plz
Answers
Answered by
3
Answer:
what are you trying to say ...
integers and negative
Answered by
4
Answer:using System;
using System.Linq;
class Solution
{
public static int Assignment(int number)
{
// Consider that int.MaxValue equals to 2147483647
var siblingString = String.Join("", number.ToString().ToCharArray().OrderByDescending(n => n));
int sibling = -1;
if (!int.TryParse(siblingString, out sibling) || sibling > 100000000)
{
return -1;
}
return sibling;
}
}
Explanation:
mark as brainliest
Similar questions