classSolution:defsecondGreaterElement(self, nums: List[int])-> List[int]:
d ={}
d[0]=[-1,-2]
d[-2]=[0,-2]
d[-1]=[-1,0]
n =[0]*len(nums)
ans =[-1]*len(nums)for i inrange(1,len(nums)):
k = d[-2][0]while nums[i]> nums[k]:
n[k]+=1if n[k]==2:
ans[k]= nums[i]
d[d[k][0]][1]= d[k][1]
d[d[k][1]][0]= d[k][0]
k = d[k][0]if k ==-1:break
d[i]=[k, d[k][1]]
d[d[k][1]][0]= i
d[k][1]= i
return ans
9. Knowledge Modeling & Ontology Engineering
How should the knowledge in a KG be modeled? – Which classes of entities do we have? – Which relations connect them? – Which constraints hold for them? → these questions are defined in the ontology …