head of a singly linked list, reverse the list, and return the reversed list.
A easy category linked list problem where we need to reverse the Linked list.For this there are two method-iterative and recurrssive method.Here we will apply the iterative method. For this method we will need to use to variable “prev” and “next_current”.Let’s move toward the code.
def reverseList(self, head: ListNode) -> ListNode:
First we will give initial value of Null to prev variable and save head of Linked list in variable “current”. The we…
Linked is type of linear data structure which is widely use to solve specific problem raise due to the limitation of arrays.
Linked list can be define as linear data structure in which the elements are not stored in contiguous memory location. In Laymen terms we can say a linked list is a collection of nodes in which each node has a data and the reference to the next node.
The first node of the linked list is called as Head and the last node of the linked list points to null. In this tutorial we will perfomer following operations:-
There is a string ”s”, of lowercase English letters that is repeated infinitely many times. Given an integer ,”n”. Find and print the number of letter “a” in string “s” in the first “ n” letters of the infinite string.
Interesting hackerrank problem where we need to find the letter “a” in first “n“ letters a given string which is repeated infinitely. Lets move towards the code.In …
There are a number of people who will be attending ACM-ICPC World Finals. Each of them may be well versed in a number of topics. Given a list of topics known by each attendee, presented as binary strings, determine the maximum number of topics a 2-person team can know. Each subject has a column in the binary string, and a ‘1’ means the subject is known while ‘0’ means it is not. Also determine the number of teams that know the maximum number of topics. Return an integer array with two elements. …