Skip to content

Instantly share code, notes, and snippets.

View see-why's full-sized avatar
😇

Iyadi Cyril see-why

😇
View GitHub Profile
@see-why
see-why / GameOfThrones.py
Created March 24, 2022 22:19
Hackerrank Game of thrones 1 challenge solution
# 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'
@see-why
see-why / MakingAnagrams.py
Created March 23, 2022 22:08
HackerRank Making Anagrams challenge solution
# 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)
@see-why
see-why / Anagram.js
Created March 22, 2022 23:34
HackerRank Anagram challenge solution
// # 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())
@see-why
see-why / Anagram.py
Created March 22, 2022 22:54
Hackerrank anagram challenge solution
# 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())
@see-why
see-why / PalindromeIndex.js
Created March 21, 2022 22:34
Hackerrank Palindrome Index challenge solution
// 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('');
@see-why
see-why / The-Love-Letter-Mystery.js
Created March 20, 2022 22:06
HackerRank The Love Letter Mystery challenge solution
// 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)
@see-why
see-why / FindtheMedian.cs
Created March 19, 2022 21:18
HackerRank Find the median challenge solution
// 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];
}
@see-why
see-why / ClosestNumbers.js
Created March 18, 2022 20:56
HackerRank Closest Numbers challenge solution
// 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];
@see-why
see-why / BeautifulBinaryString.py
Created March 17, 2022 22:26
HackerRank Beautiful Binary String challenge solution
# 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')
@see-why
see-why / AlternatingCharacters.py
Created March 16, 2022 22:34
HackerRank Alternating Characters challenge solution
# 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):