Challenge: https://www.hackerrank.com/contests/ns-code-challenges/challenges
A palindrome is a string that reads the same left-to-right and right-to-left. For example, "Madam, I'm Adam" and "Poor Dan is in a droop" are both palindromes. Note that letter case and non-alphanumeric characters should be ignored when deciding whether a string is a palindrome or not.
А string x is an anagram of another string y if you can obtain y by rearranging the letters of x. For example, "cinema" is an anagram of "iceman", and vice versa. Note that the string and its anagram must have the same length. By definition, the string is not considered as an anagram of itself. In anagrams, non-alphanumeric characters and letter case are important. For instance, "Oo" is not the same as "oO", making "Oo" an anagram of "oO" and vice versa.
Given a message, your task is to determine whether there is an anagram of the message that is also a palindrome.
Example
For message = "abab", the output should be hasPalindromicAnagram(message) = true.
Among the anagrams of "abab", there are two strings that are also palindromes ("abba" and "baab"), so the answer is true.
For message = "bob", the output should be hasPalindromicAnagram(message) = false.
The only rearrangement of the letters in the string "bob" that is a palindrome is the word itself, but this is not an anagram as defined above. Therefore, the answer is false.
For message = "heh!", the output should be hasPalindromicAnagram(message) = true.
"!heh", "h!eh" and "he!h" are all palindromes and all of them are anagrams of "heh!". Remember that according to the rules laid out above, non-alphanumeric characters are ignored in palindromes but need to be considered in anagrams.
Input Format
A string that will be checked to determine if there is an anagram of that string that is also a palindrome
Constraints
A string containing at least one alphanumeric character.
0 < message.length ≤ 20
Output Format
You should print "true" or "false" if there is an anagram of the given string that is also a palindrome
Sample Input 0
abab
Sample Output 0
true
Sample Input 1
bob
Sample Output 1
false
Sample Input 2
heh!
Sample Output 2
true
You are given an N x M maze. The grid consists of the characters '#' and '.'
A '#' represents a wall, and a '.' represents a walkable tile. In addition, there is a single character 'S' representing your starting position, and a single character 'T' representing the target position. You can only move upwards, downwards, leftwards and rightwards and you can only move to walkable tiles. Also, you can't move outside the grid.
Write a program that calculates the minimum number of moves to travel from S to T. If it is impossible to reach T from S, then output DOOMED.
Input Format
The first line contains two integers, N and M, separated by a single space. The next N lines each contain a string of length M consisting of '#', '.', 'S' or 'T'.
Constraints
1 <= N <= 1000
1 <= M <= 1000
Output Format
Output a single line containing the minimum number of moves to travel from S to T, or DOOMED if it is impossible.
Sample Input 0
7 11
...........
.#########.
...#...#...
S#.#.#.#.#T
.#...#...#.
.#########.
...........
Sample Output 0
16
Sample Input 1
4 4
..S#
..#T
.#..
#...
Sample Output 1
DOOMED
Sample Input 2
3 4
....
.S.#
T...
Sample Output 2
2
Sample Input 3
12 19
...........#.......
#.....#...#.#.....#
........S#T........
........#..........
.......#...........
......#............
.....#.............
....#..............
...#...............
..#................
.#.................
#..................
Sample Output 3
DOOMED
Definitions:
Number expressed in Negabinary
Every integer a can be written uniquely in base -2. Reference: Negative base
Element with odd occurrence in collection
Given a collection which contains an odd number of elements, each element can be paired with another element that has the same value, except for one that is left unpaired.
For example given the collection: ["cat", "dog", "mouse", "cat", "dog"]
there are two occurrences of "cat" and two occurrences of "dog" but "mouse"is left unpaired, it has an odd number of occurrences.
Problem statement:
Given a collection of numbers written in negabinary form that contains just one element with an odd number of occurrences print the negative value
Input Format
One line that will contain the collection of elements separated by spaces
Constraints
1 ≤ collection size < 10^5
1 ≤ string size by number < 10^5
Output Format
A string representing -X in negabinary
Sample Input 0
11 1 11
Sample Output 0
11
Explanation 0
The input contains -1 base -2 two times and 1 base -2 one time, 1 is the odd element, -1 in base -2 is expressed as 11
Sample Input 1
11110 11110 11100 101 11100 11100 11100
Sample Output 1
1111
Explanation 1
The input contains 10 base -2 two times, 12 base -2 four times and 5 base -2 one time, 5 is the odd element, -5 in base -2 is expressed as 1111
Given a comma-separated list of equal-length strings, check if it is possible to rearrange the strings in such a way that after the rearrangement the strings at consecutive positions would differ by exactly one character.
Example
- For input: aba,bbb,bab the output should be: false
- For input: ab,bb,aa the output should be: true
Input Format
A comma-separated list of strings containing alphanumeric characters.
Constraints
- 2 ≤ list length ≤ 10
- 1 ≤ string length ≤ 15.
Output Format
Either the string true or false
Sample Input 0
aba,bbb,bab
Sample Output 0
false
Sample Input 1
ab,bb,aa
Sample Output 1
true
Sample Input 2
q,q
Sample Output 2
false
Sample Input 3
zzzzab,zzzzbb,zzzzaa
Sample Output 3
true
A string S is called a square if there is some string T such that S = T + T. For example, the strings "", "aabaab" and "xxxx" are squares, but "a", "aabb" and "aabbaa" are not.
You are given a String s. Find the longest square string that can be obtained from s by erasingsome (possibly none, possibly all) of its characters. In other words, we are looking for the longest square that occurs in s as a subsequence. Return the length of that square.
Note that the answer is well-defined, as the square "" (the empty string) will always occur in s as a subsequence.
Input Format
An alphabetic string
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character in s will be a lowercase English letter ('a'-'z')
Output Format
You should print the lenght of the longest square that occurs in s as a subsequence
Example 1: Input: "frankfurt" Expected output: 4 The longest square that occurs in "frankfurt" is "frfr". Its length is 4.
Example 2: Input: "single" Expected output: 0 The letters in the string "single" are all distinct. Hence, the only square that occurs in this string is "". The length of this square is zero.
Sample Input 0
frankfurt
Sample Output 0
4
Sample Input 1
single
Sample Output 1
0
Sample Input 2
singing
Sample Output 2
6
Sample Input 3
aababbababbabbbbabbabb
Sample Output 3
18
Sample Input 4
x
Sample Output 4
0