Why does the code not satisfy all testcases in Hackerrank?

41 views Asked by At

I'm trying to solve the "Merge the tools" in python Hackerrank, my code satisfies the Sample Testcase but not the others. Can someone please help me figure out where I'm going wrong?

This is the link to the question: https://www.hackerrank.com/challenges/merge-the-tools/problem?isFullScreen=true

And this is what I've written within the function:

import textwrap
from collections import OrderedDict as od

def merge_the_tools(string, k):
    # your code goes here
    length = int(len(string)/k)
    words = textwrap.wrap(string,length)

    for i in words:
        new_dict = od.fromkeys(i)
        print("".join(new_dict))
1

There are 1 answers

0
SIGHUP On

Just a plain dictionary will suffice. You don't need to import anything

def merge_the_tools(string, k):
    for i in range(0, len(string), k):
        print(*{c: None for c in string[i:i+k]}, sep="")