diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e7e9d11 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..d03559d --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +JAVA_CODES \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b9a5bd0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/JAVA/src/first_non_repeating_code.java b/JAVA/src/first_non_repeating_code.java new file mode 100644 index 0000000..fb1eaf9 --- /dev/null +++ b/JAVA/src/first_non_repeating_code.java @@ -0,0 +1,33 @@ +import java.util.*; +public class first_non_repeating_code { + public static char firstNonRepeatedCharacter(String word) { + HashMap scoreboard = new HashMap<>(); + for (int i = 0; i < word.length(); i++) + { + char c = word.charAt(i); + if (scoreboard.containsKey(c)) + { + scoreboard.put(c, scoreboard.get(c) + 1); + } + else + { scoreboard.put(c, 1); + } + } + for (int i = 0; i < word.length(); i++) { + char c = word.charAt(i); + if (scoreboard.get(c) == 1) + { return c; } + + } + throw new RuntimeException("Undefined behaviour"); + + } + public static void main (String[] args) { + try{ + System.out.println(firstNonRepeatedCharacter("aabbbbbccfffffgghh")); + }catch(RuntimeException e){ + System.out.println("no non repeating value exists"); + } + + } +} diff --git a/JAVA_CODES.iml b/JAVA_CODES.iml new file mode 100644 index 0000000..a9bade1 --- /dev/null +++ b/JAVA_CODES.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Rishabh/.DS_Store b/Rishabh/.DS_Store deleted file mode 100644 index d112959..0000000 Binary files a/Rishabh/.DS_Store and /dev/null differ diff --git a/Rishabh/Prime_No_Upto_N.py b/Rishabh/Prime_No_Upto_N.py deleted file mode 100644 index aa7b087..0000000 --- a/Rishabh/Prime_No_Upto_N.py +++ /dev/null @@ -1,29 +0,0 @@ -def isPrime(num): - """Checks num for primality. Returns bool.""" - - if num == 2: - return True - elif num < 2 or not num % 2: # even numbers > 2 not prime - return False - - # factor can be no larger than the square root of num - for i in range(3, int(num ** .5 + 1), 2): - if not num % i: return False - return True - - - -def generatePrimes(n): - - primes = [2,] - noOfPrimes = 1 - testNum = 3 - while noOfPrimes < n: - if isPrime(testNum): - primes.append(testNum) - noOfPrimes += 1 - testNum += 2 - - return primes - -#Make Driver Code diff --git a/Rishabh/README.md b/Rishabh/README.md deleted file mode 100644 index efffdb3..0000000 --- a/Rishabh/README.md +++ /dev/null @@ -1 +0,0 @@ -# Coding_Exercises \ No newline at end of file diff --git a/Rishabh/README.rst b/Rishabh/README.rst deleted file mode 100644 index dd81634..0000000 --- a/Rishabh/README.rst +++ /dev/null @@ -1,102 +0,0 @@ -Python FedEx SOAP API Module -============================ - -.. image:: https://badge.fury.io/py/fedex.svg - :target: https://badge.fury.io/py/fedex - -.. image:: https://travis-ci.org/python-fedex-devs/python-fedex.svg?branch=master - :target: https://travis-ci.org/python-fedex-devs/python-fedex - -.. image:: https://requires.io/github/python-fedex-devs/python-fedex/requirements.svg?branch=master - :target: https://requires.io/github/python-fedex-devs/python-fedex/requirements/?branch=master - :alt: Requirements Status - -.. image:: https://readthedocs.org/projects/python-fedex/badge/?version=latest - :target: http://python-fedex.readthedocs.org/en/latest/?badge=latest - :alt: Documentation Status - -:Author: Greg Taylor, Radek Wojcik -:Maintainer: Python FedEx Developers -:License: BSD -:Status: Stable - -What is it? ------------ - -A light wrapper around FedEx's Webservice Soap API. We don't do much of any -validation, but we'll help you sort through the pile of SOAP objects FedEx -uses. - -Installation ------------- - -The easiest way is via pip or easy_install:: - - pip install fedex - -Start Quickly ------------ - -- Clone this repository. - -- Edit the `example_config.py` file in See `examples/ `_ with your fedex credentials -and run any of the provided examples. - -Documentation -------------- - -Refer to the documentation_ for more details on the project. Latest doc builds -are found in docs_ and doc build scripts in doc_source_. Sphinx documentation is in doc_src_. - -There are also a lot of useful examples under the examples directory within -this directory. - -Support -------- - -Issues & Questions: https://github.com/gtaylor/python-fedex/issues - -Most problems are going to require investigation or a submitted -pull request by someone from the Python FedEx Developers organization. -To contribute a new feature or service, feel free to create a pull request. -We are always looking for new contributors to help maintain the project. - -Fedex Support and Documentation -------------------------------- - -Fedex Support Email: websupport@fedex.com - -Developer Portal: http://www.fedex.com/us/developer/ - -Updates To Services: https://www.fedex.com/us/developer/web-services/process.html (FedEx Web Services Announcements) - - -Related Projects ----------------- - -- FedEx Commercial Invoice Generation, see https://github.com/radzhome/fedex-commercial-invoice - -Todos ------ - -- Increase service specific request validation -- Remove deprecated services (package movement service) -- Pickup service unit tests - -Legal ------ - -Copyright (C) 2008-2015 Greg Taylor - -Copyright (C) 2015-2016 Python FedEx Developers - -This software is licensed under the BSD License. - -python-fedex is not authored by, endorsed by, or in any way affiliated with -FedEx. - -.. _documentation: https://readthedocs.org/projects/python-fedex/ -.. _documentation2: https://pythonhosted.org/fedex/ -.. _docs: docs/ -.. _doc_source: doc_source/ -.. _doc_src: doc_src/ diff --git a/Rishabh/Reverse_Alternate_2.py b/Rishabh/Reverse_Alternate_2.py deleted file mode 100644 index c321b6f..0000000 --- a/Rishabh/Reverse_Alternate_2.py +++ /dev/null @@ -1,9 +0,0 @@ -def reverseStr( s, k): - a = list(s) - for i in range(0, len(a), 2*k): - a[i:i+k] = reversed(a[i:i+k]) - return "".join(a) - -Input --> "abcdefg" -Output --> "bacdfeg" -when s="abcdefg" , k=2 diff --git a/Rishabh/String_Int_Special.py b/Rishabh/String_Int_Special.py deleted file mode 100644 index 3c568ca..0000000 --- a/Rishabh/String_Int_Special.py +++ /dev/null @@ -1,45 +0,0 @@ -import re -x="ab2@/3cd7ef9" #fe97dc3ba2 -#x="zx32hgf78lk" -l_x=[] -for i in x: - l_x.append(i) -#l_x=x.split() -#print(l_x) - -s_c_l=re.findall('[^A-Za-z0-9]',x) -print(s_c_l) -temp=[] -for i in range(0,len(l_x)): - if(x[i].isdigit()): - for j in range(len(l_x)-1,-1,-1): - if(l_x[j].isdigit()): - temp.append(l_x.pop(j)) - #l_x.pop(j) - break - #print("True") - else: - for k in range(len(l_x)-1,-1,-1): - #print(l_x) - if(l_x[k].isalpha()): - temp.append(l_x.pop(k)) - #l_x.pop(k) - break - #print("False") - -print(temp) - -t_l=[] -for i in s_c_l: - count=0 - for j in x: - count=count+1 - if(i==j): - t_l.append(count) - break -#print(l_x) -print(t_l) -for i in t_l: - temp.insert(t_l[i-1],s_c_l[i]) - -print(temp) \ No newline at end of file diff --git a/Rishabh/binary_number_sort.py b/Rishabh/binary_number_sort.py deleted file mode 100644 index 7397c1e..0000000 --- a/Rishabh/binary_number_sort.py +++ /dev/null @@ -1,17 +0,0 @@ -a = [0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0] -#j = -1 -a1=[] -'''for i in range(len(a)): - if a[i] < 1: - j = j + 1 - a[i], a[j] = a[j], a[i]''' - - -while a: - #print("hv") - small=min(a) - a1.append(small) - #print ("sdff") - a.pop(a.index(small)) - -print(a1) diff --git a/Rishabh/bubble_sort.py b/Rishabh/bubble_sort.py deleted file mode 100644 index fad77de..0000000 --- a/Rishabh/bubble_sort.py +++ /dev/null @@ -1,22 +0,0 @@ -def bubble_sort(arr): - def swap(i, j): - arr[i], arr[j] = arr[j], arr[i] - - n = len(arr) - swapped = True - - x = -1 - while swapped: - swapped = False - x = x + 1 - for i in range(1, n-x): - if arr[i - 1] > arr[i]: - swap(i - 1, i) - swapped = True - - return arr - - -for i in range() -l=["ccab"] -res=bubble_sort(l[0]) diff --git a/Rishabh/compress_k_words.py b/Rishabh/compress_k_words.py deleted file mode 100644 index 3d79c41..0000000 --- a/Rishabh/compress_k_words.py +++ /dev/null @@ -1,38 +0,0 @@ -# A function which will take two arguements, the string and number -# of consecutive charecters to be compressed. -def compressWord(word): - #initializing a empty result string so that we can concatenate our resultant string. - res = "" - #initial value of i is 0 so that we can check the consecutiveness from starting. - i = 0 - k=2 - while i < len(word): - # it will run starting from the first element of string to the last element of string. - if i < len(word) - (k-1) and [True for j in range(5,0,-1) if word[i]*(k+j) == word[i:i+k+j]]: - #if stmt i 2: - prime_factors.add(n) - return prime_factors - -def factor_of_three_and_five(first,last): - #initializing value of count with 0 so that we can count ideal prime factors. - count = 0 - # empty list for three and five div - three_and_fives_div =[] - #loop will run starting from the first arguement to last arguement - for i in range(first,last+1): - #it will check whether the i is a multiple of 3 or 5 or not. - if (i%3==0) or (i%5==0): - # if i is a multiple of 3 or 5 then pass it to the primeFactors function defined - #above - prime_factors = primeFactors(i) - - # there are two primeFactors, so we will check whether we have two or less than - # two - if len(set(prime_factors)) <= 2: - # check whether we have 1 prime factor - if len(set(prime_factors)) == 1: - # if yes than just increment the count variable - if (3 in prime_factors) or (5 in prime_factors): - count += 1 - # if not equal to 1 then check whether that set has these elemnts or not - # but to check we have a sorted list that's why we are converting the - # returned set sorted list and again increment count if yes - elif (sorted(list(set(prime_factors))) == [3,5]): - count +=1 - - - - - - # if 1 in range(first,last+1): - # count += 1 - #just return value of count - return count - - -f = factor_of_three_and_five(200,405) -print(f) - - - - - - - -# string="aaabbccaaee" -# lst=list(string) -# #print(lst) -# count=1 -# ls=[] -# for i in range(len(lst)): -# if i+1 == len(lst): -# # print(lst[i]," ",count," ",i) -# ls.append((lst[i],count))#dict[lst[i]]=count -# if i+1 < len(lst): -# if lst[i] == lst[i+1]: -# count=count+1 -# #print(i,count,lst[i]) -# continue -# else: -# ls.append((lst[i],count))#dict[lst[i]]=count -# count=1 -# #print(i,lst[i],count,ls) -# continue -# # print(ls) -# for i in ls: -# print(i[0],i[1],sep="",end="") diff --git a/Rishabh/iot.png b/Rishabh/iot.png deleted file mode 100644 index b5dd0d9..0000000 Binary files a/Rishabh/iot.png and /dev/null differ diff --git a/Rishabh/least_common.py b/Rishabh/least_common.py deleted file mode 100644 index a363a6a..0000000 --- a/Rishabh/least_common.py +++ /dev/null @@ -1,23 +0,0 @@ -from collections import Counter -line = [4,4,4,1,1,1,1,1,1,1,2,3,4,5,6,-1,1,2] - - -temp = Counter(line) -# # print(temp.keys()) -# print(temp) - -# t_l = [0] -# ss = set(temp) -# max = 0 -# for i in ss: -# if temp[i]>max: -# t_l.insert(0,i) -# max = temp[i] -# # print(max) - -# print(t_l[0]) -# print(t_l) - -print(temp) -for k,v in temp: - print(k,v) \ No newline at end of file diff --git a/Rishabh/mini.py b/Rishabh/mini.py deleted file mode 100644 index 684a457..0000000 --- a/Rishabh/mini.py +++ /dev/null @@ -1,12 +0,0 @@ -def minimum(x): - mini = x[0] - for i in x[0:]: - if i < mini: - mini = i - return mini - - - -x=[5,1,3,9,4,2] -res=minimum(x) -print(res) diff --git a/Rishabh/nested_list_to_single.py b/Rishabh/nested_list_to_single.py deleted file mode 100644 index 4d1724d..0000000 --- a/Rishabh/nested_list_to_single.py +++ /dev/null @@ -1,3 +0,0 @@ -import itertools -a = [[1, 2], [3, 4], [5, 6]] -print(list(itertools.chain.from_iterable(a))) \ No newline at end of file diff --git a/Rishabh/pair_sum.py b/Rishabh/pair_sum.py deleted file mode 100644 index 3c9ca7a..0000000 --- a/Rishabh/pair_sum.py +++ /dev/null @@ -1,28 +0,0 @@ -list= [1,3,5,6,2,8,9,2,5] -temp = [] -target=10 -l=len(list) -hash = set() - -def order_of_n2(list,l,target): - for i in range(l): - for j in range(i+1,l): - if(list[i]+list[j] == target): - temp.append(tuple([list[i],list[j]])) - - - - - -def order_of_logn(list,l,target): - for i in range(l): - temp_var = target - list[i] - if(temp_var in hash): - #print("Found") - temp.append(tuple([temp_var,list[i]])) - hash.add(list[i]) - - -order_of_logn(list,l,target) -order_of_n2(list,l,target) -print(temp) diff --git a/Rishabh/palin_temp.py b/Rishabh/palin_temp.py deleted file mode 100644 index b5d55b9..0000000 --- a/Rishabh/palin_temp.py +++ /dev/null @@ -1,47 +0,0 @@ - -from collections import Counter -while True: - - str = list(input("Please enter the string to check\n")) - if str == str[::-1]: - print("".join(str), "Is already palindrome") - else: - c = Counter(list(str)) - # print(c) - tt = [] - for k in str: - if k not in tt: - tt.append(k) - # st = set(str) - temp_l=[] - for i in list(tt): - # print(c[i]) - if c[i]in [j for j in range(0,22) if j%2 !=0]:# == 1 or c[i]==3 or c[i]==5: - if str[len(str)//2] == i: - # print("ig",i) - pass - else: - # print("el") - temp_l.append(i) - # print(str) - str.remove(i) - # print(str) - - - # print(temp_l) - # print(str[::-1]) - # print(str) - if str == str[::-1]: - pass - else: - temp_l.append(str[len(str)//2-1]) - # To make a palindrome - # temp = str[len(str)//2] - # str[len(str)//2] = str[len(str)//2-1] - # str[len(str)//2-1] = temp - # print(str) - if len(str)<3: - print("not possible") - else: - print("Items to be deleted: ", temp_l) - print("Palindrome is:","".join(str)) diff --git a/Rishabh/palindrome_creator.py b/Rishabh/palindrome_creator.py deleted file mode 100644 index d370007..0000000 --- a/Rishabh/palindrome_creator.py +++ /dev/null @@ -1,19 +0,0 @@ -str = "eabcba" - - -def PalindromeCreator(str): - temp_l=[] - n = len(str) - rev=list(reversed(str)) - print(rev,list(str)) - for i in range(n-1): - if(str[i] == rev[i]): - pass - else: - if(str[i] == rev[i+1]): - temp_l.append(str[i]) - else: - temp_l.append(rev[i]) - print(temp_l) - -PalindromeCreator(str) diff --git a/Rishabh/pytr.py b/Rishabh/pytr.py deleted file mode 100644 index 945a729..0000000 --- a/Rishabh/pytr.py +++ /dev/null @@ -1,17 +0,0 @@ -string=input("Enter string:") -if(string!=string[::-1]): - s=set() - for i in string: - - if i not in s: - s.add(i) - - else: - s.remove(i) - - s1=" ".join(map(str,(i for i in s))) - print(s1) - - -else: - print("The string a palindrome") \ No newline at end of file diff --git a/Rishabh/re_remove_dash_string.py b/Rishabh/re_remove_dash_string.py deleted file mode 100644 index 5f2a70e..0000000 --- a/Rishabh/re_remove_dash_string.py +++ /dev/null @@ -1,8 +0,0 @@ -Fecth out the integers without hyphen and integers -import re - - -str = "11-22-33-44 trdtyj yutuyik" - -d=(re.findall('\d+',str)) -print(''.join(d)) diff --git a/Rishabh/reverse_word_by_word.py b/Rishabh/reverse_word_by_word.py deleted file mode 100644 index 3d712e5..0000000 --- a/Rishabh/reverse_word_by_word.py +++ /dev/null @@ -1,3 +0,0 @@ -new = s.strip() --> strip function will remove trailing and leading whitespaces in a string. -new = new.split( ) -- > split will convert the string to list. Did this so that I can revrese list using ::-1 slice -return ' '.join(new[::-1]) --> join function will convert the reversed list back to string. diff --git a/Rishabh/spiral_draw.py b/Rishabh/spiral_draw.py deleted file mode 100644 index 16075c5..0000000 --- a/Rishabh/spiral_draw.py +++ /dev/null @@ -1,11 +0,0 @@ -import pyautogui, time -time.sleep(5) -pyautogui.click() # click to put drawing program in focus -distance = 200 -while distance > 0: - pyautogui.dragRel(distance, 0, duration=0.2) # move right - distance = distance - 2.5 - pyautogui.dragRel(0, distance, duration=0.2) # move down - pyautogui.dragRel(-distance, 0, duration=0.2) # move left - distance = distance - 2.5 - pyautogui.dragRel(0, -distance, duration=0.2) # move up \ No newline at end of file diff --git a/Rishabh/traverse_by_index.py b/Rishabh/traverse_by_index.py deleted file mode 100644 index 3e9089b..0000000 --- a/Rishabh/traverse_by_index.py +++ /dev/null @@ -1,44 +0,0 @@ -#rl = [2,8,14,1,10,5,2,12,4,0] -input_string = input("Eneter numbers") -r = input_string.split() -# rl = list(map(int,input_string)) -rl = [int(i) for i in r] -# print(rl) -l=len(rl) -count=0 -temps=[] -c=0 -while True: - if(rl[count]>= len(rl)): - # print("ini") - - temps.append(rl.pop(count)) - count = count + 1 - # print(count) - # print(rl) - # print(temps) - #print(temp) - - - temp=rl[count] - count=rl[temp] - if(count==temp): - print("Same Index"+str(count)+str(temp)) - break - #print(rl[count]) - #break - if(count >= len(rl)): - #var1 = rl.index(count) - temps.append(rl.pop(temp)) - count = temp + 1 - # print(count) - # print(temps) - # print(rl) - c=c+1 - if(c>l): - # print("Nothing to match") - break - -print("Original List Elements = "+str(rl)) -print("Out of Index Elements "+str(temps)) -print("Number of Execution = "+ str(c)) \ No newline at end of file diff --git a/Rishabh/unique_emails.py b/Rishabh/unique_emails.py deleted file mode 100644 index d817423..0000000 --- a/Rishabh/unique_emails.py +++ /dev/null @@ -1,14 +0,0 @@ - -def UniqueEmails(email_list): - unique_one = set() - for email in email_list: - before, after = email.split('@') - if '+' in before: - before = before[:before.index('+')] - unique_one.add(before.replace('.','') + '@' + after) - return len(unique_one),unique_one - - -input_list = ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"] -uni_set = UniqueEmails(input_list) -print(uni_set) \ No newline at end of file diff --git a/Rishabh/word_char_sort.py b/Rishabh/word_char_sort.py deleted file mode 100644 index df832ec..0000000 --- a/Rishabh/word_char_sort.py +++ /dev/null @@ -1,53 +0,0 @@ -#This Section will sort the list of word alphabetically in a way that each charecter will be sorted. -# I/p=["aba","cbc","cab","babc"] -# O/p=["aab","abbc","abc","bcc"] -#----------------------SECTION 1 ------------------------------- -'''main_list = ["aba","cbc","cab","babc"] -word = [] -char = [] -temp_list = [] -temp_list1 = [] - -while main_list: - small = min(main_list) - word.append(small) - main_list.pop(main_list.index(small)) - -print(word) - - - -for i in range(0,len(word)): - for j in word[i]: - temp_list.append(j) - #print(temp_list) - #temp_list.clear() - - while temp_list: - small=min(temp_list) - temp_list1.append(small) - temp_list.pop(temp_list.index(small)) - char.append(''.join(temp_list1)) - temp_list1.clear() - - -print(char) -''' - -# This section will split a string in words so that we can use in sorting -# I/p="This is my name" -# O/p=["This","is","my","name"] - -str="This is my name" -main_list=[] -str_temp_list=[] -for i in str: - if(ord(i) == ord(" ")): - main_list.append(''.join(str_temp_list)) - str_temp_list.clear() - - else: - str_temp_list.append(i) -main_list.append(''.join(str_temp_list)) -str_temp_list.clear() -print(main_list) diff --git a/Rishabh/word_char_sort_split.py b/Rishabh/word_char_sort_split.py deleted file mode 100644 index 91c7ea5..0000000 --- a/Rishabh/word_char_sort_split.py +++ /dev/null @@ -1,73 +0,0 @@ -#This Section will sort the list of word alphabetically in a way that each charecter will be sorted. -# I/p=["aba","cbc","cab","babc"] -# O/p=["aab","abbc","abc","bcc"] -#----------------------GLOBAL DEFINITIONS ------------------------------- -#main_list = ["aba","cbc","cab","babc"] -main_list=[] -word = [] -char = [] -temp_list = [] -temp_list1 = [] -str=input("Please input your String.") - -#----------------------MINIMUM FUNCTION----------------------------------- -def minimum(x): - mini = x[0] - for i in x: - if i < mini: - mini = i - return mini -#---------------------WORD AND CHAR SORT FUNCTION------------------------- -def sort_string(): - print() - while main_list: - small = minimum(main_list) - word.append(small) - main_list.pop(main_list.index(small)) - - print("Words after Sorting\n",word) - - - - for i in range(0,len(word)): - for j in word[i]: - temp_list.append(j) - #print(temp_list) - #temp_list.clear() - - while temp_list: - small=minimum(temp_list) - temp_list1.append(small) - temp_list.pop(temp_list.index(small)) - char.append(''.join(temp_list1)) - temp_list1.clear() - - - print("Charecters after Sorting:\n",char) - - -# This section will split a string in words so that we can use in sorting -# I/p="This is my name" -# O/p=["This","is","my","name"] -#-----------------------------SPLITTING STRING------------------------ -def split_string(): - #str="This is my name" - #main_list=[] - str_temp_list=[] - count=0 - for i in str: - count = count + 1 - if(ord(i) == ord(" ") or count == (len(str))): - main_list.append(''.join(str_temp_list)) - str_temp_list.clear() - - else: - str_temp_list.append(i) - #main_list.append(''.join(str_temp_list)) - #str_temp_list.clear() - print("Splitted String:\n",main_list) - - - -split_string() -sort_string()