Horje
Yummy Future Interview Experience for Python Developer

There were 3 coding questions in 1-hour total time and it was conducted on code byte. All questions were on string based

First Question: Program to find whether HTML tags are nested correctly or not — 10 marks (Easy) Have the function HTMLElements(str) read the str parameter being passed which will be a string of HTML DOM elements and plain text. The elements that will be used are: <b>, <I>, <em>, <div>, <p>. 

For example: if str is “<div><b><p>hello world</p></b></div>” then this string of DOM elements is nested correctly so your program should return the string true.

If a string is not nested correctly, return the first element encountered where, if changed into a different element, would result in a
properly formatted string. If the string is not formatted properly, then it will only be one element that needs to be changed. For example:
if str is “<div><i>hello</i>world</b>” then your program should return the string div because if the first <div> element were changed into
a <b>, the string would be properly formatted.
Examples

Input: "<div><div><b></b></div></p>"
Output: div
Input: "<div>abc</div><p><em><i>test test test</b></em></p>

Solution:

I used stack data structure and re.split

Python3

import re
  
def HTMLElements(strParam):
   open_tags=['<div>','<i>','<em>','<p>','<b>']
   close_tags=['</div>','</i>','</em>','</p>','</b>']
     
   stack=[]
  
  
   tags=re.split('(<[^>]*>)',strParam)
   print(tags)
   for tag in tags:
       if tag in open_tags:
           stack.append(tag)
       elif tag in close_tags:
           check=close_tags.index(tag)
           if(len(stack)>0 and open_tags[check]==stack[len(stack)-1]):
               stack.pop()
   if stack:
       return stack[-1].replace('<','').replace('>',''))
   return True

Second Question: String-Based problem. Python program to find the smallest substring or smallest window of a substring in a given string containing all characters of other string — (15 marks medium)

The used window sliding algorithm is given in GFG only.

GFG Link:- /archive/find-the-smallest-window-in-a-string-containing-all-characters-of-another-string/

Solution:-

Python3

''' Python solution '''
  
  
def smallestWindow(s, p):
    n = len(s)
    if n < len(p):
        return -1
    mp = [0]*256
  
    # Starting index of ans
    start = 0
  
    # Answer
    # Length of ans
    ans = n + 1
    cnt = 0
  
    # creating map
    for i in p:
        mp[ord(i)] += 1
        if mp[ord(i)] == 1:
            cnt += 1
  
    # References of Window
    j = 0
    i = 0
  
    # Traversing the window
    while(j < n):
  
    # Calculating
        mp[ord(s[j])] -= 1
        if mp[ord(s[j])] == 0:
            cnt -= 1
  
            # Condition matching
            while cnt == 0:
                if ans > j - i + 1:
  
                # calculating answer.
                    ans = j - i + 1
                    start = i
  
                # Sliding I
                # Calculation for removing I
                mp[ord(s[i])] += 1
                if mp[ord(s[i])] > 0:
                    cnt += 1
                i += 1
        j += 1
    if ans > n:
        return "-1"
    return s[start:start+ans]
  
  
# Driver code
if __name__ == "__main__":
    s = "this is a test string"
    p = "tist"
    result = smallestWindow(s, p)
    print(result)
  
    # This code is contributed by cyclades.

Third question: String Based problem. For me it was for the first time I have seen this question, It was hard too…… (25 marks) Hard. I don’t know what I got wrong but 3/8 test cases passed and time was over.

Question: Have the function WildcardCharacters(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many characters should appear in the sequence where N will be at least 1, $ represents any digit between 0-9. Your goal is to determine if the second string exactly matches the pattern of the first string in the input. 

For example: if str is “++*{5} gheeeee” then the second string in this case does match the pattern, so your program should return the string true. If the second string does not match the pattern your program should return the string false.

The solution I wrote:- (Only 3 or 4 test cases passed out of a total of eight)

So all of the solutions could not have been solved without the help of the internet. First Two questions I already practiced from GFG and Leetcode but the third question was out of the box so I took help.

Any suggestions or critiques are warmly welcome.

Awaiting the Results and will update you soon…Hasta La Vista!!!!!!!!!

Python3

import re
def WildcardCharacters(string):
     strArr=string.split(' ')
     specChar=strArr[0]
     charStr=strArr[1].split()
    
     arr=specChar.split('')
     letters="/^[A-Za-z]+$"
    num="/[1-9]"
    i=0
    while(i<len(arr)):
          if(arr[i]=='+'):
            match=re.search(charStr[0],letters)
              if not match:
                return False
              charStr=charStr[1,len(charStr)]
          
        elif(arr[i]=='$'){
              match=re.search(charStr[0],num)
              if not match:
                  return False
             charStr=charStr[1,len(charStr)]
          
        elif(arr[i]=='*'):
            curr=charStr[0]
              j=1,k=0
              if(arr[i+1]!=None and arr[i+1]=='{'):
                k=arr[i+2]
                  i=i+4
              else:
                k=3
                  i+=1
            
              while(j<k):
                charStr=charStr[1,len(charStr)]
                if(charStr[0]!=curr):
                    return False
                j+=1
              charStr=charStr[1,len(charStr)]
              continue
    i+=1
    if(len(charStr)!=0):
        return False
     return True




Reffered: https://www.geeksforgeeks.org


Interview Experiences

Related
Tenneco US Interview Experience for PM Intern Tenneco US Interview Experience for PM Intern
Paytm Interview Experience for Backend Developer Paytm Interview Experience for Backend Developer
Infosys HackwithInfy Interview Experience for Digital Specialist Engineer(Off-Campus) Infosys HackwithInfy Interview Experience for Digital Specialist Engineer(Off-Campus)
Zepto Interview Experience for SDE-2 FTE Zepto Interview Experience for SDE-2 FTE
Reliance AJIO Interview Experience for SDE-2 FTE Reliance AJIO Interview Experience for SDE-2 FTE

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13