Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
f504682
Create Contacts.py
avinashthetech Apr 7, 2022
8b5eb9b
Merge pull request #8 from Lancelot03/Lancelot03-patch-1-2
Lancelot03 Jul 5, 2022
1a66c3d
Create Find The Parity Outlier.py
Lancelot03 Jul 6, 2022
40a5dd3
Merge pull request #9 from Lancelot03/Lancelot03-patch-5
Lancelot03 Jul 6, 2022
d9bbffd
Create The Supermarket Queue.py
Lancelot03 Jul 7, 2022
d76fba3
Merge pull request #10 from Lancelot03/Lancelot03-patch-6
Lancelot03 Jul 7, 2022
569c277
Create Rot13.py
Lancelot03 Jul 8, 2022
f04af65
Merge pull request #11 from Lancelot03/Lancelot03-patch-1-3
Lancelot03 Jul 8, 2022
9d1269e
Create Reducing Problems - Bug Fixing #8.py
Lancelot03 Jul 9, 2022
7045f4d
Merge pull request #12 from Lancelot03/Lancelot03-patch-7
Lancelot03 Jul 9, 2022
d7969c1
Create Which are in?.py
Lancelot03 Jul 10, 2022
fd1ba3f
Merge pull request #13 from Lancelot03/Lancelot03-patch-8
Lancelot03 Jul 10, 2022
c65c166
Create A Chain adding function.py
Lancelot03 Jul 11, 2022
959e23c
Merge pull request #14 from Lancelot03/Lancelot03-patch-9
Lancelot03 Jul 11, 2022
b16170d
Create A Chain adding function2.py
Lancelot03 Jul 12, 2022
18c2533
Merge pull request #15 from Lancelot03/Lancelot03-patch-10
Lancelot03 Jul 12, 2022
b3a2d84
Create Reg.py
Lancelot03 Jul 13, 2022
bd82bad
Merge pull request #16 from Lancelot03/Lancelot03-patch-11
Lancelot03 Jul 13, 2022
b7a4652
Create Shortest Word.py
Lancelot03 Jul 14, 2022
08ee210
Merge pull request #17 from Lancelot03/Lancelot03-patch-12
Lancelot03 Jul 14, 2022
c147a92
Create Find the smallest integer in the array.py
Lancelot03 Jul 16, 2022
58c16a6
Merge pull request #18 from Lancelot03/Lancelot03-patch-13
Lancelot03 Jul 16, 2022
2b5504f
Create Rakuten Hiring.py
Lancelot03 Jul 17, 2022
3a907b4
Merge pull request #19 from Lancelot03/Lancelot03-patch-14
Lancelot03 Jul 17, 2022
44ed66e
Create Square(n) Sum.py
Lancelot03 Jul 19, 2022
c03dea6
Merge pull request #20 from Lancelot03/Lancelot03-patch-15
Lancelot03 Jul 19, 2022
f0516be
Create Formation of Linked list.py
Lancelot03 Jul 20, 2022
419d656
Merge pull request #21 from Lancelot03/Lancelot03-patch-16
Lancelot03 Jul 20, 2022
abf5fb4
Create Linked List Creation.py
Lancelot03 Jul 23, 2022
f0bfe4b
Merge pull request #22 from Lancelot03/Lancelot03-patch-17
Lancelot03 Jul 23, 2022
c98c12d
Create Linked List Insersion.py
Lancelot03 Jul 24, 2022
83ff4d9
Merge pull request #23 from Lancelot03/Lancelot03-patch-18
Lancelot03 Jul 24, 2022
a6c8a3f
Encryption
avinashthetech Jul 26, 2022
a8e0611
Merge pull request #24 from avinashpdpd/main
Lancelot03 Jul 26, 2022
d7652d0
Create Linked List Insersion1.py
Lancelot03 Jul 27, 2022
aa0313a
Merge pull request #26 from Lancelot03/Lancelot03-patch-20
Lancelot03 Jul 27, 2022
5047b18
Create argmaxx.py
Lancelot03 Aug 1, 2022
a934ed3
Merge pull request #27 from Lancelot03/Lancelot03-patch-21
Lancelot03 Aug 1, 2022
eebad1e
Create num.py
Lancelot03 Aug 2, 2022
f5f1cf5
Merge pull request #28 from Lancelot03/Lancelot03-patch-22
Lancelot03 Aug 2, 2022
5ab5040
Create new.py
Lancelot03 Aug 4, 2022
7b68453
Merge pull request #29 from Lancelot03/Lancelot03-patch-23
Lancelot03 Aug 4, 2022
7ed2d0a
Update new.py
Lancelot03 Aug 5, 2022
e73943f
Merge pull request #30 from Lancelot03/Lancelot03-patch-24
Lancelot03 Aug 5, 2022
da80fb0
Create new1.py
Lancelot03 Aug 6, 2022
207f26c
Merge pull request #31 from Lancelot03/Lancelot03-patch-25
Lancelot03 Aug 6, 2022
e5523a8
Create New2.py
Lancelot03 Aug 7, 2022
14d5ca8
Merge pull request #32 from Lancelot03/Lancelot03-patch-26
Lancelot03 Aug 7, 2022
b3599d8
Update and rename New2.py to Find the middle of a given linked list.py
Lancelot03 Aug 8, 2022
055a7f9
Merge pull request #33 from Lancelot03/Lancelot03-patch-27
Lancelot03 Aug 8, 2022
163cbf7
Update and rename new1.py to Linked List.py
Lancelot03 Aug 10, 2022
ab7e132
Merge pull request #34 from Lancelot03/Lancelot03-patch-28
Lancelot03 Aug 10, 2022
e9d6ed8
Create New 1.py
Lancelot03 Aug 11, 2022
5389947
Merge pull request #35 from Lancelot03/Lancelot03-patch-29
Lancelot03 Aug 11, 2022
4930ceb
Create new2.py
Lancelot03 Aug 12, 2022
e54998c
Merge pull request #36 from Lancelot03/Lancelot03-patch-30
Lancelot03 Aug 12, 2022
87400b2
Create new3.py
Lancelot03 Aug 13, 2022
1cf9cd7
Merge pull request #37 from Lancelot03/Lancelot03-patch-31
Lancelot03 Aug 13, 2022
a2655dd
Update and rename New 1.py to Doubly Linked List insertion.py
Lancelot03 Aug 14, 2022
336890b
Merge pull request #38 from Lancelot03/Lancelot03-patch-32
Lancelot03 Aug 14, 2022
3717c5b
Create new 2.py
Lancelot03 Aug 15, 2022
a16258c
Merge pull request #39 from Lancelot03/Lancelot03-patch-33
Lancelot03 Aug 15, 2022
d6ffdfb
Create NEW 2.py
Lancelot03 Aug 16, 2022
6358a90
Merge pull request #40 from Lancelot03/Lancelot03-patch-34
Lancelot03 Aug 16, 2022
e7473b0
Update and rename new 2.py to Flattening a Linked List.py
Lancelot03 Aug 18, 2022
a1f03d1
Create Beautiful Triplets.py
Lancelot03 Aug 19, 2022
fb7a09a
Merge pull request #41 from Lancelot03/Lancelot03-patch-35
Lancelot03 Aug 19, 2022
3b01326
Create Counting Valleys1.py
Lancelot03 Aug 19, 2022
f1337eb
Merge pull request #42 from Lancelot03/Lancelot03-patch-36
Lancelot03 Aug 19, 2022
c88650b
Create ChiefHopper.py
Lancelot03 Aug 19, 2022
e05070a
Merge pull request #43 from Lancelot03/Lancelot03-patch-37
Lancelot03 Aug 19, 2022
63ef7bd
Create Python
Lancelot03 Aug 20, 2022
427a1b4
Merge pull request #44 from Lancelot03/Lancelot03-patch-38
Lancelot03 Aug 20, 2022
9fad828
Create P1.
Lancelot03 Aug 28, 2022
c6011ad
Merge pull request #45 from Lancelot03/Lancelot03-patch-39
Lancelot03 Aug 28, 2022
586a949
Create P2.py
Lancelot03 Aug 29, 2022
4e97523
Merge pull request #46 from Lancelot03/Lancelot03-patch-40
Lancelot03 Aug 29, 2022
59f2770
Update P1.
Lancelot03 Aug 30, 2022
2e4bcf2
Merge pull request #47 from Lancelot03/Lancelot03-patch-41
Lancelot03 Aug 30, 2022
ac124bb
Create P3
Lancelot03 Aug 31, 2022
8d75533
Merge pull request #48 from Lancelot03/Lancelot03-patch-42
Lancelot03 Aug 31, 2022
4196d4d
Update and rename P1. to Capitalize!.py
Lancelot03 Sep 1, 2022
2213e45
Merge pull request #49 from Lancelot03/Lancelot03-patch-43
Lancelot03 Sep 1, 2022
45c43cb
Update and rename P2.py to Find duplicate in an array of N+1 Integers.py
Lancelot03 Sep 2, 2022
217e3ed
Merge pull request #50 from Lancelot03/Lancelot03-patch-44
Lancelot03 Sep 2, 2022
c89f906
Create p
Lancelot03 Sep 3, 2022
779b8fe
Update and rename P3 to Pascal's Triangle.py
Lancelot03 Sep 4, 2022
a71093b
Merge pull request #51 from Lancelot03/Lancelot03-patch-45
Lancelot03 Sep 4, 2022
466f136
Update and rename NEW 2.py to Next Permutation.py
Lancelot03 Sep 5, 2022
cd8bcf6
Merge pull request #52 from Lancelot03/Lancelot03-patch-46
Lancelot03 Sep 5, 2022
f0907ed
Update and rename new2.py to Maximum Subarray.py
Lancelot03 Sep 5, 2022
454b874
Update and rename new3.py to Sort color.py
Lancelot03 Sep 6, 2022
59f30dd
Merge pull request #53 from Lancelot03/Lancelot03-patch-47
Lancelot03 Sep 6, 2022
38b7d65
Update and rename num.py to best time to by stocks.py
Lancelot03 Sep 6, 2022
f37fadc
Merge pull request #54 from Lancelot03/Lancelot03-patch-48
Lancelot03 Sep 6, 2022
f8d00f4
Update and rename p to Rotate Matrix.py
Lancelot03 Sep 7, 2022
c432237
Merge pull request #55 from Lancelot03/Lancelot03-patch-49
Lancelot03 Sep 7, 2022
45f718a
Create Merge Intervale.py
Lancelot03 Sep 8, 2022
4c1afba
Merge pull request #56 from Lancelot03/Lancelot03-patch-50
Lancelot03 Sep 8, 2022
35106e1
Update and rename Python to Merge Sorted Array.py
Lancelot03 Sep 9, 2022
05188d9
Merge pull request #57 from Lancelot03/Lancelot03-patch-51
Lancelot03 Sep 9, 2022
af65f4d
Create Find the Duplicate Number.py
Lancelot03 Sep 10, 2022
41bc72d
Merge pull request #58 from Lancelot03/Lancelot03-patch-52
Lancelot03 Sep 10, 2022
2bcaa93
Create Missing and repeating numbers.py
Lancelot03 Sep 12, 2022
7693ab7
Merge pull request #59 from Lancelot03/Lancelot03-patch-53
Lancelot03 Sep 12, 2022
032f281
Create Count Inversions.py
Lancelot03 Sep 12, 2022
8218896
Merge pull request #60 from Lancelot03/Lancelot03-patch-54
Lancelot03 Sep 12, 2022
ab975fb
Create Search a 2D Matrix.py
Lancelot03 Sep 13, 2022
d75930a
Merge pull request #61 from Lancelot03/Lancelot03-patch-55
Lancelot03 Sep 13, 2022
7af7ca3
Create Pow(x, n).py
Lancelot03 Sep 13, 2022
d70e382
Merge pull request #62 from Lancelot03/Lancelot03-patch-56
Lancelot03 Sep 13, 2022
45ba8c3
Create Majority Element.py
Lancelot03 Sep 13, 2022
d475b1c
Merge pull request #63 from Lancelot03/Lancelot03-patch-57
Lancelot03 Sep 13, 2022
5192180
Create Majority Element2.py
Lancelot03 Sep 14, 2022
35e74d4
Create Py
Lancelot03 Sep 16, 2022
9c01033
Merge pull request #64 from Lancelot03/Lancelot03-patch-58
Lancelot03 Sep 16, 2022
3669f7f
Update and rename Py to Unique Path.py
Lancelot03 Sep 17, 2022
bd87789
Merge pull request #65 from Lancelot03/Lancelot03-patch-59
Lancelot03 Sep 17, 2022
009ae07
Create 4Sum.py
Lancelot03 Sep 19, 2022
b2a6605
Merge pull request #66 from Lancelot03/Lancelot03-patch-60
Lancelot03 Sep 19, 2022
2e0f065
Create Longest Consecutive Sequence.py
Lancelot03 Sep 20, 2022
44c8bce
Merge pull request #67 from Lancelot03/Lancelot03-patch-61
Lancelot03 Sep 20, 2022
88e7127
Create py
Lancelot03 Sep 21, 2022
ab9ae23
Merge pull request #68 from Lancelot03/Lancelot03-patch-62
Lancelot03 Sep 21, 2022
4bb53d4
Create Py2
Lancelot03 Sep 22, 2022
4af8d04
Merge pull request #69 from Lancelot03/Lancelot03-patch-63
Lancelot03 Sep 22, 2022
b8c2533
Create Python.py
Lancelot03 Sep 23, 2022
1610b09
Merge pull request #70 from Lancelot03/Lancelot03-patch-64
Lancelot03 Sep 23, 2022
46c953f
Create Python2
Lancelot03 Sep 24, 2022
cea9d47
Merge pull request #71 from Lancelot03/Lancelot03-patch-65
Lancelot03 Sep 24, 2022
345f625
Create python3
Lancelot03 Sep 25, 2022
1186224
Update and rename Py2 to Longest Substring Without Repeating Characte…
Lancelot03 Sep 26, 2022
cef371c
Merge pull request #72 from Lancelot03/Lancelot03-patch-66
Lancelot03 Sep 26, 2022
3cb16e2
Create Py3
Lancelot03 Sep 27, 2022
affb3ba
Merge pull request #73 from Lancelot03/Lancelot03-patch-67
Lancelot03 Sep 27, 2022
f8ccfc1
Create py3
Lancelot03 Sep 28, 2022
9d0f535
Merge pull request #74 from Lancelot03/Lancelot03-patch-68
Lancelot03 Sep 28, 2022
9f19572
py changes
Lancelot03 Sep 29, 2022
0ec4f09
Update and rename py to Set Matrix Zero.cpp
Lancelot03 Oct 2, 2022
3b8b7a8
Merge pull request #75 from Lancelot03/Lancelot03-patch-69
Lancelot03 Oct 2, 2022
159b3b6
Create Pascal's Triangle.cpp
Lancelot03 Oct 2, 2022
fe73f7d
Merge pull request #76 from Lancelot03/Lancelot03-patch-70
Lancelot03 Oct 2, 2022
f70f304
Create Py4
Lancelot03 Oct 3, 2022
b872186
Merge pull request #78 from Lancelot03/Lancelot03-patch-71
Lancelot03 Oct 3, 2022
b715137
Create Py2
Lancelot03 Oct 6, 2022
dc35d74
Merge pull request #79 from Lancelot03/Lancelot03-patch-72
Lancelot03 Oct 6, 2022
8ff212d
Update and rename Py4 to Next Permutation C++.cpp
Lancelot03 Oct 6, 2022
04aeaec
Update and rename Py2 to Kadane’s Algorithm : Maximum Subarray Sum in…
Lancelot03 Oct 6, 2022
4c19799
Create Py
Lancelot03 Oct 8, 2022
f831cc6
Rename Py to Py.py
Lancelot03 Oct 9, 2022
39e4695
Create Stock Buy and sale.cpp
Lancelot03 Oct 10, 2022
3b5ba6d
Merge pull request #80 from Lancelot03/Lancelot03-patch-73
Lancelot03 Oct 10, 2022
450eab6
Adding 1 code
Arpit-00 Oct 11, 2022
c08ed75
Adding 1 code
Arpit-00 Oct 11, 2022
e080718
Merge pull request #81 from Arpit-00/patch-1
Lancelot03 Oct 11, 2022
11d1c8e
Create Majority Elements 2.cpp
Arpit-00 Oct 11, 2022
dfea587
Create Grid Unique Paths.cpp
Arpit-00 Oct 11, 2022
9d634be
Merge pull request #82 from Arpit-00/main
Lancelot03 Oct 11, 2022
96c8742
Create Count Reverse Pairs.cpp
Arpit-00 Oct 11, 2022
daf7176
Merge pull request #83 from Arpit-00/main
Lancelot03 Oct 11, 2022
416f946
Create Count the number of subarrays with given xor K.cpp
Lancelot03 Oct 11, 2022
21f0df9
Merge pull request #85 from Lancelot03/Lancelot03-patch-74
Lancelot03 Oct 11, 2022
3570149
Create Length of Longest Substring without any Repeating Character.cpp
Lancelot03 Oct 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions 4Sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def fourSum(self, nums: List[int], target: int) -> List[List[int]]:
nums.sort()
res, quad=[] , []
def kSum(k, start, target):
if k != 2:
for i in range(start, len(nums)-k+1):
if i > start and nums[i]==nums[i - 1]:
continue
quad.append(nums[i])
kSum(k - 1, i + 1, target - nums[i])
quad.pop()
return
l, r = start, len(nums)-1
while l<r:
if nums[l]+nums[r]<target:
l+=1
elif nums[l] + nums[r]>target:
r -=1
else:
res.append(quad + [nums[l],nums[r]])
l+=1
while l<r and nums[l]== nums[l -1]:
l+=1

kSum(4, 0, target)
return res
3 changes: 3 additions & 0 deletions A Chain adding function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class add(int):
def __call__(self, n):
return add(self + n)
3 changes: 3 additions & 0 deletions A Chain adding function2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class add(int):
def __call__(self, n):
return add(self + n)
29 changes: 29 additions & 0 deletions Beautiful Triplets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import math
import os
import random
import re
import sys
def beautifulTriplets(d, arr):
res = 0

for el in arr:
if el + d in arr and el + 2*d in arr:
res += 1

return res
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

first_multiple_input = input().rstrip().split()

n = int(first_multiple_input[0])

d = int(first_multiple_input[1])

arr = list(map(int, input().rstrip().split()))

result = beautifulTriplets(d, arr)

fptr.write(str(result) + '\n')

fptr.close()
15 changes: 15 additions & 0 deletions Capitalize!.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import math
import os
import random
import re
import sys
def solve(s):
for x in s[:].split():
s = s.replace(x, x.capitalize())
return s
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
result = solve(s)
fptr.write(result + '\n')
fptr.close()
42 changes: 42 additions & 0 deletions ChiefHopper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
n = int(input())
high = low = 0
arr = []

for i in input().split():
arr.append(int(i))
if(int(i) > high):
high = int(i)
if(int(i) < low):
low = int(i)

def tester(x, arr):
energy = x
answer = True
for height in arr:
if(height > energy):
energy -= (height - energy)
if(energy < 0):
return(False)
else:
energy += (energy - height)
return(answer)

cont = True
i = (high + low) // 2
dic = {}
while(cont):
if(dic.get(i-1, tester(i-1, arr))):
# i is too high
high = i
i = (high + low) // 2
else:
if(dic.get(i, tester(i, arr))):
cont = False
else:
# i is too low, double it and set low to current i
low = i
i = ((i + high + 1) // 2)
if(i == 0):
i = 1

print(i)
44 changes: 44 additions & 0 deletions Contacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Trie:
def __init__(self):
self.count = 1
self.children = {}

def add(self, name):
node = self
for let in name:
if let in node.children.keys():
node.children[let].count += 1
node = node.children[let]
else:
node.children[let] = Trie()
node = node.children[let]

def find(self, name):
node = self
for let in name:
if let in node.children.keys():
res = node.children[let].count
node = node.children[let]
else:
res = 0
break

return res

def print(self):
print("count = {} keys = {}".format(self.count, self.children.keys()))
for key in self.children.keys():
self.children[key].print()

if __name__ == "__main__":
t = int(input().strip())
trie = Trie()

for _ in range(t):
args = input().strip().split()

if args[0] == 'add':
trie.add(args[1])
elif args[0] == 'find':
print(trie.find(args[1]))

7 changes: 7 additions & 0 deletions Count Inversions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def getInversions(arr, n) :
icount=0
for i in range(n):
for j in range(i,n):
if arr[i]>arr[j]:
icount+=1
return icount
18 changes: 18 additions & 0 deletions Count Reverse Pairs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<bits/stdc++.h>
using namespace std;
int reversePairs(vector < int > & arr) {
int Pairs = 0;
for (int i = 0; i < arr.size(); i++) {
for (int j = i + 1; j < arr.size(); j++) {
if (arr[i] > 2 * arr[j]) Pairs++;
}
}
return Pairs;
}


int main()
{
vector<int> arr{1,3,2,3,1};
cout<<"The Total Reverse Pairs are "<<reversePairs(arr);
}
23 changes: 23 additions & 0 deletions Count the number of subarrays with given xor K.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<bits/stdc++.h>
using namespace std;
class Solution{
public:
int solve(vector<int> &A, int B) {
long long c=0;
for(int i=0;i<A.size();i++){
int current_xor = 0;
for(int j=i;j<A.size();j++){
current_xor^=A[j];
if(current_xor==B) c++;
}
}
return c;
}
};

int main()
{ vector<int> A{ 4,2,2,6,4 };
Solution obj;
int totalCount= obj.solve(A,6);
cout<<"The total number of subarrays having a given XOR k is "<<totalCount<<endl;
}
30 changes: 30 additions & 0 deletions Counting Valleys1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import math
import os
import random
import re
import sys

def countingValleys(steps, path):
valleys = 0
cur_level = 0
for steps in path:
if(steps == 'U'):
cur_level += 1
if(cur_level == 0):
valleys += 1
elif(steps == 'D'):
cur_level -= 1
return(valleys)

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

steps = int(input().strip())

path = input()

result = countingValleys(steps, path)

fptr.write(str(result) + '\n')

fptr.close()
7 changes: 7 additions & 0 deletions Doubly Linked List insertion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def push(self, new_data):
new_node = Node(data = new_data)
new_node.next = self.head
new_node.prev = None
if self.head is not None:
self.head.prev = new_node
self.head = new_node
12 changes: 12 additions & 0 deletions Find The Parity Outlier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def find_outlier(integers):
even=[]
odd=[]
for i in integers:
if i % 2 == 0:
even.append(i)
else:
odd.append(i)
if len(even)==1:
return even[0]
else:
return odd[0]
11 changes: 11 additions & 0 deletions Find duplicate in an array of N+1 Integers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
numRay = [0, 4, 3, 2, 7, 8, 2, 3, 1]
arr_size = len(numRay)
for i in range(arr_size):

x = numRay[i] % arr_size
numRay[x] = numRay[x] + arr_size

print("The repeating elements are : ")
for i in range(arr_size):
if (numRay[i] >= arr_size*2):
print(i, " ")
14 changes: 14 additions & 0 deletions Find the Duplicate Number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def findDuplicate(self, nums: List[int]) -> int:
slow, fast =0,0
while True:
slow = nums[slow]
fast=nums[nums[fast]]
if slow == fast:
break

slow2=0
while True:
slow = nums[slow]
slow2 = nums[slow2]
if slow == slow2:
return slow
42 changes: 42 additions & 0 deletions Find the middle of a given linked list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Node:
def __init__(self, data):
self.data = data
self.next = None

class NodeOperation:
def pushNode(self, head_ref, data_val):
new_node = Node(data_val)
new_node.next = head_ref
head_ref = new_node
return head_ref
def printNode(self, head):
while (head != None):
print('%d->' % head.data, end="")
head = head.next
print("NULL")
def getLen(self, head):
temp = head
len = 0

while (temp != None):
len += 1
temp = temp.next

return len

def printMiddle(self, head):
if head != None:
len = self.getLen(head)
temp = head
midIdx = len // 2
while midIdx != 0:
temp = temp.next
midIdx -= 1
print('The middle element is [%d]' % temp.data)

head = None
temp = NodeOperation()
for i in range(5, 0, -1):
head = temp.pushNode(head, i)
temp.printNode(head)
temp.printMiddle(head)
4 changes: 4 additions & 0 deletions Find the smallest integer in the array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def find_smallest_int(arr):
arr.sort()
a=arr[0:1]
return arr[0]
Loading