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/CodeChef/Starters 146/Back Front
Prev
CodeChefCodeChef
5 Star
Starters 146

Back Front

GreedyStringMath
Loading...
Solve on CodeChef

Problem Statement

Official algorithmic problem description and constraints.

Open on CodeChef

For the lowercase English letter α, let ord(α) denote the order of α in the alphabet, under the standard ordering a,b,c,…,z.

For example, ord(b)=2,ord(j)=10,0, and ord(z)=26.

You are given a string S containing N lowercase English letters.

You can perform the following 2 operations on it:

  1. Choose a subsequence of the string that equals "back", and delete the subsequence from S.
  2. Then, choose any character α such that ord(α) has at most two divisors, and insert α at the start of S.
  3. Choose a subsequence of the string that equals "front", and delete the subsequence from S.
  4. Then, choose any character α such that ord(α) has strictly more than two divisors, and append α to S.

You may perform these two operations as many times as you like (possibly, zero), and in any order.

Find the minimum possible length of the final string after doing so.

Solutions & Walkthrough

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

Connecting secure classroom stream...
Back to Starters 146
Previous Problem