Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/Codeforces/Codeforces Round 945/C. Cat, Fox and Double Maximum
Prev
CodeforcesCodeforces
Expert
Codeforces Round 945

C. Cat, Fox and Double Maximum

SortingGreedyOrdered Set
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

Fox loves permutations! She came up with the following problem and asked Cat to solve it:

You are given an even positive integer π‘› and a permutation† π‘ of length π‘›.

The score of another permutation π‘ž of length π‘› is the number of local maximums in the array π‘Ž of length π‘›, where π‘Žπ‘–=𝑝𝑖+π‘žπ‘– for all π‘– (1≀𝑖≀𝑛). In other words, the score of π‘ž is the number of π‘– such that 1<𝑖<𝑛 (note the strict inequalities), π‘Žπ‘–βˆ’1<π‘Žπ‘–, and π‘Žπ‘–>π‘Žπ‘–+1 (once again, note the strict inequalities).

Find the permutation π‘ž that achieves the maximum score for given π‘› and π‘. If there exist multiple such permutations, you can pick any of them.

A permutation of length π‘› is an array consisting of π‘› distinct integers from 1 to π‘› in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (𝑛=3 but there is 4 in the array).

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Codeforces Round 945
Previous Problem