Skip to content

Commit 5c8036d

Browse files
committed
Added hint method for URLmaking
1 parent b5f7cda commit 5c8036d

File tree

1 file changed

+60
-3
lines changed

1 file changed

+60
-3
lines changed

edualgo/algorithm.py

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def isPermutation(self,input1,input2,hint=False):
262262
return mapp1==mapp2
263263

264264
def isPermutation_hint(self):
265-
message ="""
265+
message = """
266266
Two String Permutations
267267
------------------------------------
268268
@@ -339,6 +339,64 @@ def URLify(self,input_str,key):
339339
input2 += key
340340
return input2
341341

342+
def URLify_hint(self):
343+
message = """
344+
Making a URL From a String
345+
------------------------------------
346+
347+
Purpose : Making a URL by replacing the spaces with a key value entered
348+
by the user
349+
Method : string manipulation
350+
351+
Time Complexity : Worst Case - O(n), n = length of the string
352+
353+
Hint :
354+
Take a blank string, and add data from the input string to the blank
355+
string to prepare the final URL
356+
357+
Pseudocode :
358+
--> Take a blank string s2
359+
--> for i in [0,length of input string]
360+
if(not a whitespace)
361+
add to s2
362+
elif(whitespace and next place is also whitespace)
363+
return s2
364+
elif(whitespace and next place not whitespace)
365+
add the key value to the blank string
366+
367+
Visualization:
368+
369+
Given String To Make URL :
370+
371+
"Python is love"
372+
373+
Key : "%20"
374+
375+
Break The Given String : /*/ ----> whitespace
376+
377+
+--------+-------+----+-------+------+
378+
| Python | /*/ | is | /*/ | love |
379+
+--------+-------+----+-------+------+
380+
^ ^ ^
381+
^ ^ ^
382+
^ ^ ^
383+
384+
1 2 3
385+
386+
We will take 1, 2 and 3 sucessively and in place of whitespaces we will
387+
concatenate the key value.
388+
389+
Empty String Addition :
390+
391+
+-+ +--------+ +-------+ +----+ +-------+ +------+
392+
| | + | Python | + | %20 | + | is | + | %20 | + | love |
393+
+-+ +--------+ +-------+ +----+ +-------+ +------+
394+
395+
Learn More about String Concatenation Below -
396+
https://en.wikipedia.org/wiki/Concatenation
397+
"""
398+
print_msg_box(message)
399+
342400
def isPalindromicPermutation(self,input1):
343401
mapp = {}
344402
for i in range(len(input1)):
@@ -413,5 +471,4 @@ def rotateImage(self,img_arr,n):
413471
img_arr[i][last] = top
414472

415473
s = string_algorithms()
416-
a = s.isPermutation("aabbccdd","abcbccdd",True)
417-
print(a)
474+
s.URLify_hint()

0 commit comments

Comments
 (0)