This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.hackerrank.com/challenges/game-of-thrones/problem?isFullScreen=true | |
def gameOfThrones(s): | |
# Write your code here | |
dict = collections.Counter(s) | |
max_value = max(dict.values()) | |
if(max_value == 1): | |
return 'NO' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.hackerrank.com/challenges/making-anagrams/problem?isFullScreen=true | |
def makingAnagrams(s1, s2): | |
# Write your code here | |
a = collections.Counter(s1) | |
b = collections.Counter(s2) | |
sum_of_commons = sum((a & b).values()) | |
return (len(s1)-sum_of_commons) + (len(s2)-sum_of_commons) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # https://www.hackerrank.com/challenges/anagram/problem?isFullScreen=true | |
def anagram(s): | |
# Write your code here | |
if len(s)%2: return -1 | |
l = len(s)//2 | |
a = collections.Counter(s[:l]) | |
b = collections.Counter(s[l:]) | |
return l-sum((a & b).values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.hackerrank.com/challenges/anagram/problem?isFullScreen=true | |
def anagram(s): | |
# Write your code here | |
if len(s)%2: return -1 | |
l = len(s)//2 | |
a = collections.Counter(s[:l]) | |
b = collections.Counter(s[l:]) | |
return l-sum((a & b).values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.hackerrank.com/challenges/palindrome-index/problem?isFullScreen=true | |
function palindromeIndex(s) { | |
// Write your code here | |
function isPalendrome(s, index){ | |
let result = false; | |
let subString = s.substring(0, index) + s.substring(index+1); | |
let reverseString = subString.split('').reverse().join(''); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.hackerrank.com/challenges/the-love-letter-mystery/problem?isFullScreen=true | |
function theLoveLetterMystery(s) { | |
// Write your code here | |
let operations = 0; | |
for (let i=0; i<s.length/2; i++){ | |
let char = s.charCodeAt(i) | |
let alternate = s.charCodeAt(s.length - (1 + i)) | |
if(char != alternate) { | |
operations+= Math.abs(char-alternate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.hackerrank.com/challenges/find-the-median/problem?isFullScreen=true | |
public static int findMedian(List<int> arr) | |
{ | |
arr.Sort(); | |
int median_index = arr.Count/2; | |
return arr[median_index]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.hackerrank.com/challenges/closest-numbers/problem?isFullScreen=true | |
function closestNumbers(arr) { | |
// Write your code here | |
arr = arr.sort((a,b) => (a -b)); | |
let minDiff = arr[1] - arr[0]; | |
let elements = []; | |
for(let i = 0; i < arr.length - 1; i++) { | |
let diff = arr[i + 1] - arr[i]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.hackerrank.com/challenges/countingsort2/problem?isFullScreen=true | |
def beautifulBinaryString(b): | |
# Write your code here | |
if '010' not in b: | |
return 0 | |
else: | |
return b.count('010') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.hackerrank.com/challenges/alternating-characters/problem?isFullScreen=true | |
def alternatingCharacters(s): | |
# Write your code here | |
result=0 | |
if 'A' not in s or 'B' not in s: | |
result = len(s)-1 | |
return result | |
i=0 | |
while i<(len(s)-1): |
NewerOlder