Professional Documents
Culture Documents
This is a quickstart section, please read this document before proceeding with the
videos in the next part.
1) This section is designed for advanced programmers who are already familiar with
Python and Programming Concepts and topics like Data Structures in Python. These
students can skip Python Basics videos and can jump to Machine Learning section and
get their hands dirty with code. 😉
2) The quickstart sections are about Python Libraries, which give you a head-start
if you want to start Machine Learning in less time. For more detailed introduction
to libraries watch the respective sections of Numpy, Pandas, Matplotlib etc. You
can install these libraries using pip. For example -
3) If you are new to programming, then the sections starting from Python Basics are
recommended. You won't miss anything if you start from Python Basics (next Module)
and skip this one.
P1
D
P2
A
P3
C
P4
A
P5
B
P6
D
P7
Node* insertInMiddle(Node* head, int x)
{
Node *temp=new Node(x);
Node *slow,*fast;
if(head==NULL){
head=temp;
return head;
}
slow=head;
fast=head->next;
while(fast&& fast->next){
slow=slow->next;
fast=fast->next->next;
}
temp->next=slow->next;
slow->next=temp;
return head;
}
P8
void deleteNode(Node *node)
{
node->data = node->next->data;
node->next = node->next->next;
P9 a)
class Solution {
public:
ListNode* sortList(ListNode* head) {
struct ListNode *ptr,*cpt;
int temp;
ptr=head;
if(head==NULL)
return head;
while(ptr->next!=NULL){
cpt=ptr->next;
while(cpt!=NULL){
if(ptr->val>cpt->val){
temp=ptr->val;
ptr->val=cpt->val;
cpt->val=temp;
}
cpt=cpt->next;
}
ptr=ptr->next;
}
return head;
}
};
P9 b)
class Solution {
public:
ListNode* removeZeroSumSublists(ListNode* head) {
map<int,ListNode*>mp;
ListNode* curr=head;
int sum=0;
while(curr){
sum=sum+curr->val;
if(sum==0){
head=curr->next;
mp.clear();
curr=curr->next;
continue;
}
if(mp.find(sum)!=mp.end()){
ListNode* alpha=mp[sum];
ListNode* left=alpha->next;
int deleteSum=sum;
while(left!=curr){
deleteSum=left->val;
mp.erase(deleteSum);
left=left->next;
}
alpha->next=curr->next;
curr=curr->next;
}
else{
mp[sum]=curr;
curr=curr->next;
}
}
return head;
}
};
P10
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode* t = new ListNode(0);
t->next = head;
ListNode *p = t;
while(p->next!=NULL&&p->next->next!=NULL){
if(p->next->val == p->next->next->val){
int dup = p->next->val;
while(p->next!=NULL&&p->next->val==dup){
p->next = p->next->next;
}
}else{
p=p->next;
}
}
return t->next;
}
};
P11
while(p->next!=NULL)
{
c1++;
p=p->next;
}
while(q->next!=NULL)
{
c2++;
q=q->next;
}
int d=abs(c1-c2);
p=head1;
q=head2;
if(c1>c2)
{
for(int i=0; i<d; i++)
p=p->next;
}
else
{
P12
Node* segregate(Node *head) {
P13
slow=slow->next;
fast=fast->next->next;
if(slow==fast)
return true;
}
return false;
}
P14
if (slow== fast){
int res = 1;
Node *temp = slow;
while (temp->next != slow)
{
res++;
temp = temp->next;
}
return res;
}
}