PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Citadel

Optimize password transform and discount scheduling

Last updated: Mar 29, 2026

Quick Overview

Optimize password transform and discount scheduling evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  • Medium
  • Citadel
  • Coding & Algorithms
  • Software Engineer

Optimize password transform and discount scheduling

Company: Citadel

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

Part 1 — Transform to palindromic k-periodic string: Input: a lowercase string currentPassword and integer k. Constraints: 1 <= k < len(currentPassword) <= 2*10^5, and len(currentPassword) is divisible by k. Operation: you may change any character to any lowercase letter; the cost is the number of positions changed. Goal: convert currentPassword to newPassword such that (a) newPassword is a palindrome, and (b) newPassword[i] = newPassword[i + k] for all valid i (0-based). Return the minimum number of character changes required and describe the algorithm with time and space complexity. Example: currentPassword = "abzzbz", k = 3 → one optimal newPassword is "zbzzbz"; answer = 1. Part 2 — Minimize processing cost with daily discount: Input: integer n; arrays filterCost[1..n], startDay[1..n], endDay[1..n]; and integer discountPrice. For each day d, the set of active images is { i | startDay[i] <= d <= endDay[i] }. Without a discount, day d costs sum(filterCost[i] over active images i). You may apply the discount at most once per day; if applied on day d, the total cost that day is exactly discountPrice. Goal: process all n images over their required day ranges to minimize the total cost across all days; return the minimum total cost modulo 1,000,000,007. Provide the algorithm and its time and space complexity. Example: n = 3; filterCost = [2,3,4]; startDay = [1,1,2]; endDay = [2,3,4]; discountPrice = 6. Per-day sums: day1=5, day2=9, day3=7, day4=4. Using the discount on days 2 and 3 gives total 5 + 6 + 6 + 4 = 21.

Quick Answer: Optimize password transform and discount scheduling evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Solution

# Solution Alignment The prompt asks for an implementation-level answer. The safest way to present it is to define the state, maintain clear invariants, then walk through complexity and tests. ## Problem Restatement Part 1 — Transform to palindromic k-periodic string: Input: a lowercase string currentPassword and integer k. Constraints: 1 <= k < len(currentPassword) <= 2*10^5, and len(currentPassword) is divisible by k. Operation: you may change any character to any lowercase letter; the cost is the number of positions changed. Goal: convert currentPassword to newPassword such that (a) newPassword is a palindrome, and (b) newPassword[i] = newPassword[i + k] for all valid i (0-based). Return the minimum number of character changes required and describe the algorithm with time and space complexity. Example: currentPassword = "abzzbz", k = 3 → one optimal newPassword is "zbzzbz"; answer = 1. Part 2 — Minim... ## Recommended Approach Define a state that captures exactly the remaining decision information. Fill base cases first, then transition from smaller subproblems to larger ones. For games, use score difference or minimax DP; for counting, sum the valid predecessor states. ## Correctness The implementation should maintain an invariant after each loop or operation that directly matches the problem statement. At termination, that invariant implies the returned value has considered every valid candidate exactly once, or has preserved the required data-structure state after every API call. ## Complexity Typical DP time is number_of_states times transition_cost. Space can often be reduced when transitions only need the previous layer or diagonal. ## Edge Cases and Tests Empty input, length 1, invalid symbols, negative values where allowed, ties under optimal play, and large counts requiring modulo arithmetic.

Related Interview Questions

  • Implement a single-producer multi-consumer ring buffer - Citadel (medium)
  • Sort a Nearly Sorted Array - Citadel (hard)
  • Compute BBO and NBBO from order data - Citadel (medium)
  • Design dynamic weighted random sampling with updates - Citadel (medium)
  • Implement task queue with insert, delete, execute - Citadel (medium)
|Home/Coding & Algorithms/Citadel

Optimize password transform and discount scheduling

Citadel logo
Citadel
Aug 1, 2025, 12:00 AM
MediumSoftware EngineerTake-home ProjectCoding & Algorithms
12
0

Optimize password transform and discount scheduling

Part 1 — Transform to palindromic k-periodic string: Input: a lowercase string currentPassword and integer k. Constraints: 1 <= k < len(currentPassword) <= 2*10^5, and len(currentPassword) is divisible by k. Operation: you may change any character to any lowercase letter; the cost is the number of positions changed. Goal: convert currentPassword to newPassword such that (a) newPassword is a palindrome, and (b) newPassword[i] = newPassword[i + k] for all valid i (0-based). Return the minimum number of character changes required and describe the algorithm with time and space complexity. Example: currentPassword = "abzzbz", k = 3 → one optimal newPassword is "zbzzbz"; answer = 1.

Part 2 — Minimize processing cost with daily discount: Input: integer n; arrays filterCost[1..n], startDay[1..n], endDay[1..n]; and integer discountPrice. For each day d, the set of active images is { i | startDay[i] <= d <= endDay[i] }. Without a discount, day d costs sum(filterCost[i] over active images i). You may apply the discount at most once per day; if applied on day d, the total cost that day is exactly discountPrice. Goal: process all n images over their required day ranges to minimize the total cost across all days; return the minimum total cost modulo 1,000,000,007. Provide the algorithm and its time and space complexity. Example: n = 3; filterCost = [2,3,4]; startDay = [1,1,2]; endDay = [2,3,4]; discountPrice = 6. Per-day sums: day1=5, day2=9, day3=7, day4=4. Using the discount on days 2 and 3 gives total 5 + 6 + 6 + 4 = 21.

Constraints & Assumptions

  • Preserve the scope, facts, inputs, and requested outputs from the prompt above.
  • If the prompt leaves a detail unspecified, state a reasonable assumption before relying on it.
  • Keep the answer interview-ready: concise enough to present, but concrete enough to implement or evaluate.

Clarifying Questions to Ask

  • Clarify input sizes, value ranges, mutability, return format, and tie-breaking.
  • State the target time and space complexity before coding.
  • Call out edge cases such as empty inputs, duplicates, invalid values, overflow, and boundary sizes.

What a Strong Answer Covers

  • A clear algorithm with the right data structures and enough pseudocode or code-level detail to implement it.
  • A correctness argument that explains why the algorithm covers all required cases.
  • Time and space complexity, plus at least one alternative approach when relevant.
  • Focused tests for normal cases, edge cases, and failure modes.

Follow-up Questions

  • How would the approach change if the input were streaming or too large for memory?
  • What invariants would you assert in production code?
  • Which tests would catch off-by-one, duplicate, or tie-breaking bugs?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Citadel•More Software Engineer•Citadel Software Engineer•Citadel Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.