Find if Array Can Be Sorted Problem

Find if Array Can Be Sorted Problem — ExecCode Easy DSA Practice

Solve the Find if Array Can Be Sorted problem on ExecCode. Free online easy DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a 0-indexed array of positive integers nums. Your task is to compute the required answer and return true if you can sort the array in ascending order, else return false. In one operation, you can swap any two adjacent elements if they have the same number of set bits. You are allowed to do this operation any number of times (including zero).

Examples

Input {"nums": [1, 2, 3]}; Output No. Input {"nums": [1, 0, 2]}; Output Yes. Input {"nums": [5, 3, 1, 7]}; Output Yes

Constraints

1 <= nums.length <= 100 1 <= nums[i] <= 2^8

Practice Find if Array Can Be Sorted free on ExecCode. Browse DSA problems, topic map, and placement guides.