Skip to content

Commit

Permalink
core: day_20
Browse files Browse the repository at this point in the history
  • Loading branch information
bluemincoder authored Apr 14, 2024
1 parent 831c4cf commit 2db56d9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions easy/day_20/problem.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Imagine you're handed a positive integer n .

Your task is to construct a permutation a1, a2, . . ., an such that for any pair of indices l and r where 1 ≤ l < r ≤ n , the sum al + a{l+1} + . . . + ar is never divisible by r - l + 1 .

In simpler terms, you need to create a sequence where no consecutive subsequence of elements sums up to a number divisible by the length of that subsequence plus one.

For instance, if n = 5 , a valid permutation could be [3, 2, 5, 4, 1] because:
- 3 + 2 = 5 is not divisible by 2 + 1 = 3 ,
- 2 + 5 = 7 is not divisible by 2 + 1 = 3 ,
- 5 + 4 = 9 is not divisible by 2 + 1 = 3 , and so on.

Input:
- The number of test cases t ( 1 ≤ t ≤ 100 ).
- For each test case: an integer n ( 1 ≤ n ≤ 100 ), the size of the permutation.

Output:
- If no such permutation exists, print -1.
- Otherwise, print n distinct integers p1, p2, . . ., pn ( 1 ≤ pi ≤ n ) representing a permutation satisfying the given condition. If multiple solutions exist, any valid permutation is acceptable.
11 changes: 11 additions & 0 deletions easy/day_20/sample_test_cases.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Example

input
3
1
2
3
output
1
1 2
-1
1 change: 1 addition & 0 deletions easy/day_20/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//write your code here

0 comments on commit 2db56d9

Please sign in to comment.