Perfect Numbers

Asked at GoogleOnsite

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

  1. 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: 196 has distinct nonzero digits and its middle digit 9 is not below both neighbours. 1546 fails because 4 is below both 5 and 6, 320 contains a 0, and 34321 repeats 3. Single-digit 7 has no digit with two neighbours, so it is perfect.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.