Daily Practice Problem

Here your today's daily dose.


Your Daily Dose #7


This problem was recently asked by Twitter:



You are given an array of k sorted singly linked lists. Merge the linked lists into a single sorted linked list and return it.

Your starting point:


class Node(object):

def __init__(self, val, next=None):

self.val = val

self.next = next


def __str__(self):

c = self

answer = ""

while c:

answer += str(c.val) if c.val else ""

c = c.next

return answer


def merge(lists):

# Fill this in.


a = Node(1, Node(3, Node(5)))

b = Node(2, Node(4, Node(6)))

print merge([a, b])

# 123456








**This problem is taken from Interview Pro.



#interview #CodingChallenge #CodingProblem #InterviewProblems #TwitterInterviewProblem #TwitterInterview #DailyCodingProblems

CONTACT

INFO

D Block, United College of Engineering and Research, Naini, Allahabad. 

211009

© 2023 SAN FRAN SUPERHUNT. PROUDLY CREATED WITH WIX.COM