Perfect Numbers
Asked at Google
Reported by the problem's creator, not verified
A positive integer is perfect when its digits are pairwise distinct, none of its digits is 0, and no digit that has a neighbour on each side is smaller than both of them. For example, 196, 23 and 12463 are perfect, while 1546 (the 4 is below both neighbours), 320 (it contains a 0) and 34321 (the 3 repeats) are not.
Implement the class PerfectNumbers.
Examples
Example 1
Input: init =
[], operations =[["is_perfect",[196]],["is_perfect",[23]],["is_perfect",[12463]],["is_perfect",[1546]],["is_perfect",[320]],["is_perfect",[34321]],["is_perfect",[7]]]Output:
[true,true,true,false,false,false,true]Explanation:
196has distinct nonzero digits and its middle digit9is not below both neighbours.1546fails because4is below both5and6,320contains a0, and34321repeats3. Single-digit7has no digit with two neighbours, so it is perfect.