Category Archives: SRM Div-2 Level-2

PalindromeMaker : TopCoder Problem 5881

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

Problem Statement:
A palindrome is a string that is spelled the same forward and backward. We want to rearrange letters of the given string baseString so that it becomes a palindrome.

You will be given a String baseString. Return the palindrome that can be made from baseString. When more than one palindrome can be made, return the lexicographically earliest (i.e., the one that occurs first in alphabetical order). Return “” (the empty string) if no palindromes can be made from baseString.
Continue reading

Advertisements

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

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