Skip to content

Instantly share code, notes, and snippets.

View praveeng1618's full-sized avatar

Praveen Kumar praveeng1618

View GitHub Profile
@praveeng1618
praveeng1618 / longsubstring.py
Created September 17, 2019 17:28
In a given string , we have to find the length of longest sub string with out repeating characters
r=input("enter string")
nums = list(r)
a=[[]]
def subsets(nums):
for i in range(len(nums)+1):
for j in range(i+1,len(nums)+1):
sub = nums[i:j]
a.append(sub)
return a
subsets(nums)
@praveeng1618
praveeng1618 / mysql_cheat_sheet.md
Created September 30, 2019 07:06 — forked from bradtraversy/mysql_cheat_sheet.md
MySQL Cheat Sheet

MySQL Cheat Sheet

Help with SQL commands to interact with a MySQL database

MySQL Locations

  • Mac /usr/local/mysql/bin
  • Windows /Program Files/MySQL/MySQL version/bin
  • Xampp /xampp/mysql/bin

Add mysql to your PATH

@praveeng1618
praveeng1618 / PythagoreanTriplet.py
Last active October 17, 2019 18:53
Given a list of numbers, find if there exists a pythagorean triplet in that list. A pythagorean triplet is 3 variables a, b, c where a^2 + b^2 = c^2
import sys
t = [int(x) for x in input().split()]
if len(t) < 3 :
print(False)
sys.exit()
for i in range(len(t)):
for j in range(i+1,len(t)):
for k in range(j+1,len(t)):
if ((t[i]**2)+(t[j]**2)) == (t[k]**2):
@praveeng1618
praveeng1618 / indicesof1st&lastduplicate.py
Last active October 17, 2019 18:53
Given a sorted array, A, with possibly duplicated elements, find the indices of the first and last occurrences of a target element, x. Return -1 if the target is not found.
flist=[]
slist=[]
count = 0
A=[int(x) for x in input().split()]
target = int(input())
for x in range(len(A)) :
if target == A[x] :
flist.append(x)
count+=1
@praveeng1618
praveeng1618 / PokemonPower.py
Created September 29, 2019 06:37
maximum power
power=[]
klist=[]
def pokemon(q):
for j in range(q):
z, y = input().split()
y=int(y)
if z=='a':
power.append(y)
elif z=='i':
for s in range(len(power)):
@praveeng1618
praveeng1618 / ProductOfRemaining.py
Created September 29, 2019 06:19
Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. For example, if our input was [1, 2, 3, 4, 5], the expected output would be [120, 60, 40, 30, 24]. If our input was [3, 2, 1], the expected output would be [2, 3, 6].
arr = [int(x) for x in input().split()]
res=[]
def multiply(lst):
j = 1
for i in range(len(lst)):
j = j * lst[i]
return j
def product(arr,k,p):
arr[i]=1
@praveeng1618
praveeng1618 / look-and-say.py
Created October 17, 2019 18:51
A look-and-say sequence is defined as the integer sequence beginning with a single digit in which the next term is obtained by describing the previous term.
stri,n = input().split()
n = int(n)
print(stri)
def fun(init):
stri = ""
i = 0
while i < len(init):
j = i + 1
count = 1
while j <= len(init)-1 :
@praveeng1618
praveeng1618 / Parantheisis.py
Last active October 19, 2019 09:54
your'e given a string of parenthesis. return minimum number of parenthesis need to be removed , in order to make string valid. "valid" means each open parenthesis has a matching closed parenthesis
par = input()
list = []
invalid = 0
for i in range(len(par)):
if par[i] == '(':
list.append(par[i])
elif par[i] == ')':
if len(list) == 0:
invalid = invalid + 1
else:
@praveeng1618
praveeng1618 / TwoSum.py
Created January 9, 2024 09:09
1. Two Sum Leetcode
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
a = [() for i in range(2)]
for i in range(0,len(nums)):
for j in range(i+1,len(nums)):
if target == nums[i]+nums[j]:
return [i,j]
@praveeng1618
praveeng1618 / Running_Sum _of_1d_Array.py
Created January 15, 2024 04:31
1480. Running Sum of 1d Array Leetcode
class Solution:
def runningSum(self, nums: List[int]) -> List[int]:
Sum = 0
for i in range(0,len(nums)):
Sum = Sum + nums[i]
nums[i] = Sum
return nums