← All problemsSign in

Chef and Chefness

CodeChefRating 2627Open on judge ↗

Chef has a string S with length N. As Chef really likes his name, he defines the chefness of a string as the number of ways to find the string "chef" as a subsequence in S; formally, it's the number of ways to choose four indices i, j, k, l such that Si = 'c', Sj = 'h', Sk = 'e', Sl = 'f' and 1 ≤ i ≤ j ≤ k ≤ l ≤ N. For example, the chefness of "chehefc" is 3 (with subsequences given by indices (1,

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start