Skip to content

Commit c707169

Browse files
committed
Added python loops and problem solving solution
1 parent 74b6832 commit c707169

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ This repository is part of the [Competitive Programmig guide](https://github.com
7070
| Array-DS |[C++](problem-solving/array-ds/solution.cpp)| [C++](problem-solving/array-ds/solution.py)|
7171
|Print Linked List|[C++](problem-solving/linked-list/print-linked-list.cpp)|[Python](problem-solving/linked-list/print-linked-list.py)|
7272
|Preorder Traversal Tree|[C++](c++/preorder-tree)|[Python](problem-solving/preorder-tree.py)|
73-
|PostOrder Traversal Tree|[C++](problem-solving/postorder.cpp)|[Python](problem-solving/postoder.py)|
73+
|PostOrder Traversal Tree|[C++](problem-solving/postorder.cpp)|[Python]||Insert Node at the head of Linked List| |[C++](problem-solving/linked-list/insert-node-at-the-head.cpp)|
74+
|Print reverse of a linked list| |[C++](problem-solving/linked-list/print_reverse.cpp)|
75+
|Get the value of thenode at a specific position from the tail| |[C++](problem-solving/linked-list/get_node_from_tail.cpp)|
7476

7577
## Python
7678

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//https://www.hackerrank.com/challenges/get-the-value-of-the-node-at-a-specific-position-from-the-tail/problem
2+
int getNode(SinglyLinkedListNode* head, int positionFromTail) {
3+
// Check if the linked list is empty
4+
if(head == NULL)
5+
return -1;
6+
int number_of_nodes = get_number_of_nodes(head);
7+
int position = number_of_nodes-positionFromTail;
8+
int counter = 0;
9+
while(head != NULL)
10+
{
11+
counter++;
12+
if(position == counter)
13+
{
14+
return head->data;
15+
}
16+
head = head->next;
17+
}
18+
// Something went wrong
19+
return -1;
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://www.hackerrank.com/challenges/insert-a-node-at-the-head-of-a-linked-list/problem
2+
SinglyLinkedListNode* insertNodeAtHead(SinglyLinkedListNode* llist, int data) {
3+
SinglyLinkedListNode *new_node = new SinglyLinkedListNode(data);
4+
new_node -> data = data;
5+
new_node->next = (llist);
6+
llist = new_node;
7+
return llist;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//https://www.hackerrank.com/challenges/print-the-elements-of-a-linked-list-in-reverse/problem
2+
void reversePrint(SinglyLinkedListNode* head) {
3+
if(head == NULL)
4+
return;
5+
reversePrint(head->next);
6+
cout << head->data<<endl;
7+
}

0 commit comments

Comments
 (0)