Monthly Archives: March 2013

FewestFactors : TopCoder Problem 5886

[The problem appeared in TopCoder SRM 272 (Div-1, Level-1) and SRM 271 (Div-2, Level-2)]
Problem link: http://community.topcoder.com/stat?c=problem_statement&pm=5886

Problem Statement:
You will be given some decimal digits in a int[] digits. Build an integer with the minimum possible number of factors, using each of the digits exactly once (be sure to count all factors, not only the prime factors). If more than one number has the same (minimum) number of factors, return the smallest one among them.
Continue reading

Advertisements

CompletingBrackets : TopCoder Problem 5977

[The problem appeared in TopCoder SRM 280 (Div-1, Level-1) and TopCoder SRM 280 (Div-2, Level-2)]

Problem link: http://community.topcoder.com/stat?c=problem_statement&pm=5977

Problem Statement:
A series of brackets is complete if we can pair off each left bracket ‘[‘ with a right bracket ‘]’ that occurs later in the series. Every bracket must participate in exactly one such pair.

Given a String text add the minimal number of brackets to the beginning and/or end of text to make it complete. Return the result.
Continue reading

SpamDetector : TopCoder Problem 2229

[The problem appeared in TopCoder SRM 205 (Div-1, Level-1) and TopCoder SRM 205 (Div-2, Level-2)]

Problem link: http://community.topcoder.com/stat?c=problem_statement&pm=2229

Problem Statement:
You are writing part of a spam detection system. Your job is to analyze the subject lines of e-mail messages and return a count of known spam signalling keywords in the subject lines. Your task is made more difficult by the spammers who try to hide the keywords in several ways. Here we will consider just one obfuscation technique: duplicating characters. Duplicating characters means taking an existing character in a word and inserting more copies of that character into the same place in the word. This process can then be repeated on a different character in the word. The spam signalling keyword “credit” might be modified to “creddiT”, “CredittT” or “ccrreeeddiitt”, etc., but not “credict”.

For the purposes of this problem we will consider subject lines which contain only letters and spaces. The “words” in the subject line are delimited by spaces. A word in the subject line is considered a “match” if the entire word is the same as at least one entire keyword, after possibly removing some duplicated characters from the subject word. A keyword that matches only part of a subject word or a subject word that matches only part of a keyword does not count. Note that if a keyword contains a double letter, the subject word must also contain (at least) a double letter in the same position to match (“double letter” means two consecutive letters in the word that are the same). For this application, all matches (and the use of the term “same”) are case insensitive.

Given a subject line and a list of keywords, return the count of words in the subject line which “match” words in the keyword list. If multiple words in the subject line match the same keyword, they are each counted, but a word in the subject line that matches multiple keywords is only counted once.
Continue reading

AmountApproximation : TopCoder Problem 4845

[The problem appeared in TopCoder SRM 274 (Div-2, Level-3)]

Problem link: http://community.topcoder.com/stat?c=problem_statement&pm=4845

Problem Statement:
We must pay D dollars. Unfortunately, we only have bills of two denominations: p1 dollars and p2 dollars. So, we want to overpay as little as possible.

You will be given ints D, p1 and p2. Return the minimum number of dollars greater than or equal to D that can be paid with the given bills. Assume that we have an infinite supply of both p1 and p2 dollar bills.
Continue reading