You are not logged in. Please login at www.codechef.com to post your questions!

×

CHN09 - Editorial

PROBLEM LINK:

Contest

Author: ???
Tester: Kevin Atienza, Jingbo Shang
Editorialist: Kevin Atienza

PREREQUISITES:

Strings, loops

PROBLEM:

Given a string consisting of as and bs, what is the minimum number of letters to be changed so that all letters are the same?

EXPLANATION:

Count the as and bs, and print the smaller count. (There's really nothing more to it.) To make all letters the same, they will either be all as or all bs, so either all bs or all as need to be changed. Since we want the minimum, the answer is the smaller one.

There are only very few non-AC verdicts for this problem, and the only mistakes are (1) compile errors and (2) failing to initialize the array (to contain the string) properly.

Compile errors are some of the most unproductive verdicts in a contest, because they can easily be discovered and fixed (by simply compiling the code!). Though there are no penalty points for compile errors, remember that this is a short contest, so saving a few units of time and effort helps.

Failing to initialize the array properly can happen in one of the following ways:

  • By failing to initialize the array at all.
  • By failing to allocate an array large enough to contain the input. Remember to look at the constraints to know how much you need to allocate. Remember that in C++, you need an array of length $n+1$ to store a string of length $n$, because strings should be terminated by a null character ('\0').

This is mostly a C/C++ problem though. The simplest ways to take a string input in Java don't involve allocating an array yourself, so this problem doesn't happen.

This is the easiest problem in the contest, so you should try to spend little time to get this one AC'ed, to give you more time to solve the others.

Time Complexity:

$O(n)$

AUTHOR'S AND TESTER'S SOLUTIONS:

[setter][333]
[tester][444]
[editorialist][555]

[333]: The link is provided by admins after the contest ends and the solutions are uploaded on the CodeChef Server. [444]: The link is provided by admins after the contest ends and the solutions are uploaded on the CodeChef Server. [555]: The link is provided by admins after the contest ends and the solutions are uploaded on the CodeChef Server.

This question is marked "community wiki".

asked 26 Jan '16, 07:19

kevinsogo's gravatar image

7★kevinsogo
1.7k586142
accept rate: 11%

edited 15 Feb '16, 20:40

admin's gravatar image

0★admin ♦♦
19.8k350498541

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,643
×349
×96
×42
×4

question asked: 26 Jan '16, 07:19

question was seen: 1,423 times

last updated: 15 Feb '16, 20:40