SlideShare a Scribd company logo
1 of 9
Download to read offline
LeetCode – Power of Two (Easy)
𝑂(log 𝑛) π‘ π‘œπ‘™π‘’π‘‘π‘–π‘œπ‘›
class Solution:
def isPowerOfTwo(self, n: int) -> bool:
if n <= 0:
return False
while n>1:
if n%2 == 0:
n = n/2
else:
return False
return True
LeetCode – Valid Parentheses (Easy)
𝑂(𝑛) π‘ π‘œπ‘™π‘’π‘‘π‘–π‘œπ‘›
class Solution:
def isValid(self, s: str) -> bool:
new_s = ' '
for text in s:
if new_s[-1] == '{' and text == '}':
new_s = new_s[:-1]
continue
elif new_s[-1] == '(' and text == ')':
new_s = new_s[:-1]
continue
elif new_s[-1] == '[' and text == ']':
new_s = new_s[:-1]
continue
elif new_s[-1] == '{' and (text == ')' or text == ']'):
return False
elif new_s[-1] == '(' and (text == ']' or text == '}'):
return False
elif new_s[-1] == '[' and (text == ')' or text == '}'):
return False
new_s += text
if new_s[1:] == '':
return True
else:
return False
LeetCode – Find Minimum in Rotated Sorted Array (Medium)
𝑂(𝑛) π‘ π‘œπ‘™π‘’π‘‘π‘–π‘œπ‘›
class Solution:
def findMin(self, nums: List[int]) -> int:
prev = nums[0] - 1
for num in nums:
if prev > num:
return num
prev = num
return nums[0]
𝑂 log 𝑛 π‘ π‘œπ‘™π‘’π‘‘π‘–π‘œπ‘›
class Solution:
def findMin(self, nums: List[int]) -> int:
cur = nums
while len(cur)>0:
leng = len(cur)
if leng == 1:
return cur[0]
mid = int(leng/2)
if len(cur[:mid]) > 1:
if cur[:mid][0] > cur[:mid][-1] and cur[:mid][-1] < cur[mid:][0]:
cur = cur[:mid]
elif cur[:mid][0] < cur[:mid][-1] and cur[:mid][0] < cur[mid:][-1]:
return cur[:mid][0]
else:
cur = cur[mid:]
elif len(cur[:mid]) == 0:
cur = cur[mid:]
elif len(cur[:mid]) == 1:
if cur[:mid][0] > cur[mid:][-1]:
cur = cur[mid:]
else:
return cur[:mid][0]
Thank You

More Related Content

What's hot (11)

String in c programming
String in c programmingString in c programming
String in c programming
Β 
String functions in C
String functions in CString functions in C
String functions in C
Β 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
Β 
C programming - String
C programming - StringC programming - String
C programming - String
Β 
Python strings
Python stringsPython strings
Python strings
Β 
Matlab calculus
Matlab calculusMatlab calculus
Matlab calculus
Β 
String in python lecture (3)
String in python lecture (3)String in python lecture (3)
String in python lecture (3)
Β 
Strings
StringsStrings
Strings
Β 
Ruby data types and objects
Ruby   data types and objectsRuby   data types and objects
Ruby data types and objects
Β 
Implementation Of String Functions In C
Implementation Of String Functions In CImplementation Of String Functions In C
Implementation Of String Functions In C
Β 
1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expression1.5 & 1.6 regular languages &amp; regular expression
1.5 & 1.6 regular languages &amp; regular expression
Β 

Similar to Coding Test Review 3

GMAT Diagnostic Test Q2 - Problem Solving - Number Properties : Indices
GMAT Diagnostic Test Q2 - Problem Solving - Number Properties : IndicesGMAT Diagnostic Test Q2 - Problem Solving - Number Properties : Indices
GMAT Diagnostic Test Q2 - Problem Solving - Number Properties : Indices4gmatprep
Β 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdfGaneshPawar819187
Β 
SAT MATHS- numbers property-indices
SAT MATHS- numbers property-indicesSAT MATHS- numbers property-indices
SAT MATHS- numbers property-indicesSKY HAWKS' ACADEMY
Β 
Python Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdfPython Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdfRahul Jain
Β 
COL106_Assignments.pdf
COL106_Assignments.pdfCOL106_Assignments.pdf
COL106_Assignments.pdfAyushSingh226386
Β 
5. Summing Series.pptx
5. Summing Series.pptx5. Summing Series.pptx
5. Summing Series.pptxHassanShah396906
Β 
Please help me fix this code! will upvote. The code needs to produce .pdf
Please help me fix this code! will upvote.  The code needs to produce .pdfPlease help me fix this code! will upvote.  The code needs to produce .pdf
Please help me fix this code! will upvote. The code needs to produce .pdfclimatecontrolsv
Β 
Please help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfPlease help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfclimatecontrolsv
Β 

Similar to Coding Test Review 3 (11)

GMAT Diagnostic Test Q2 - Problem Solving - Number Properties : Indices
GMAT Diagnostic Test Q2 - Problem Solving - Number Properties : IndicesGMAT Diagnostic Test Q2 - Problem Solving - Number Properties : Indices
GMAT Diagnostic Test Q2 - Problem Solving - Number Properties : Indices
Β 
fds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdffds Practicle 1to 6 program.pdf
fds Practicle 1to 6 program.pdf
Β 
Python Programming
Python Programming Python Programming
Python Programming
Β 
SAT MATHS- numbers property-indices
SAT MATHS- numbers property-indicesSAT MATHS- numbers property-indices
SAT MATHS- numbers property-indices
Β 
Ch8b
Ch8bCh8b
Ch8b
Β 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Β 
Python Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdfPython Cheat Sheet 2.0.pdf
Python Cheat Sheet 2.0.pdf
Β 
COL106_Assignments.pdf
COL106_Assignments.pdfCOL106_Assignments.pdf
COL106_Assignments.pdf
Β 
5. Summing Series.pptx
5. Summing Series.pptx5. Summing Series.pptx
5. Summing Series.pptx
Β 
Please help me fix this code! will upvote. The code needs to produce .pdf
Please help me fix this code! will upvote.  The code needs to produce .pdfPlease help me fix this code! will upvote.  The code needs to produce .pdf
Please help me fix this code! will upvote. The code needs to produce .pdf
Β 
Please help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfPlease help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdf
Β 

More from SEMINARGROOT

Metric based meta_learning
Metric based meta_learningMetric based meta_learning
Metric based meta_learningSEMINARGROOT
Β 
Sampling method : MCMC
Sampling method : MCMCSampling method : MCMC
Sampling method : MCMCSEMINARGROOT
Β 
Demystifying Neural Style Transfer
Demystifying Neural Style TransferDemystifying Neural Style Transfer
Demystifying Neural Style TransferSEMINARGROOT
Β 
Towards Deep Learning Models Resistant to Adversarial Attacks.
Towards Deep Learning Models Resistant to Adversarial Attacks.Towards Deep Learning Models Resistant to Adversarial Attacks.
Towards Deep Learning Models Resistant to Adversarial Attacks.SEMINARGROOT
Β 
The ways of node embedding
The ways of node embeddingThe ways of node embedding
The ways of node embeddingSEMINARGROOT
Β 
Graph Convolutional Network
Graph  Convolutional NetworkGraph  Convolutional Network
Graph Convolutional NetworkSEMINARGROOT
Β 
Denoising With Frequency Domain
Denoising With Frequency DomainDenoising With Frequency Domain
Denoising With Frequency DomainSEMINARGROOT
Β 
Bayesian Statistics
Bayesian StatisticsBayesian Statistics
Bayesian StatisticsSEMINARGROOT
Β 
Time Series Analysis - ARMA
Time Series Analysis - ARMATime Series Analysis - ARMA
Time Series Analysis - ARMASEMINARGROOT
Β 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine LearningSEMINARGROOT
Β 
Generative models : VAE and GAN
Generative models : VAE and GANGenerative models : VAE and GAN
Generative models : VAE and GANSEMINARGROOT
Β 
Effective Python
Effective PythonEffective Python
Effective PythonSEMINARGROOT
Β 
Understanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence FunctionsUnderstanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence FunctionsSEMINARGROOT
Β 
Attention Is All You Need
Attention Is All You NeedAttention Is All You Need
Attention Is All You NeedSEMINARGROOT
Β 
WWW 2020 XAI Tutorial Review
WWW 2020 XAI Tutorial ReviewWWW 2020 XAI Tutorial Review
WWW 2020 XAI Tutorial ReviewSEMINARGROOT
Β 
Coding test review 2
Coding test review 2Coding test review 2
Coding test review 2SEMINARGROOT
Β 
Locality sensitive hashing
Locality sensitive hashingLocality sensitive hashing
Locality sensitive hashingSEMINARGROOT
Β 
Coding Test Review1
Coding Test Review1Coding Test Review1
Coding Test Review1SEMINARGROOT
Β 
Strong convexity on gradient descent and newton's method
Strong convexity on gradient descent and newton's methodStrong convexity on gradient descent and newton's method
Strong convexity on gradient descent and newton's methodSEMINARGROOT
Β 

More from SEMINARGROOT (20)

Metric based meta_learning
Metric based meta_learningMetric based meta_learning
Metric based meta_learning
Β 
Sampling method : MCMC
Sampling method : MCMCSampling method : MCMC
Sampling method : MCMC
Β 
Demystifying Neural Style Transfer
Demystifying Neural Style TransferDemystifying Neural Style Transfer
Demystifying Neural Style Transfer
Β 
Towards Deep Learning Models Resistant to Adversarial Attacks.
Towards Deep Learning Models Resistant to Adversarial Attacks.Towards Deep Learning Models Resistant to Adversarial Attacks.
Towards Deep Learning Models Resistant to Adversarial Attacks.
Β 
The ways of node embedding
The ways of node embeddingThe ways of node embedding
The ways of node embedding
Β 
Graph Convolutional Network
Graph  Convolutional NetworkGraph  Convolutional Network
Graph Convolutional Network
Β 
Denoising With Frequency Domain
Denoising With Frequency DomainDenoising With Frequency Domain
Denoising With Frequency Domain
Β 
Bayesian Statistics
Bayesian StatisticsBayesian Statistics
Bayesian Statistics
Β 
Time Series Analysis - ARMA
Time Series Analysis - ARMATime Series Analysis - ARMA
Time Series Analysis - ARMA
Β 
Differential Geometry for Machine Learning
Differential Geometry for Machine LearningDifferential Geometry for Machine Learning
Differential Geometry for Machine Learning
Β 
Generative models : VAE and GAN
Generative models : VAE and GANGenerative models : VAE and GAN
Generative models : VAE and GAN
Β 
Effective Python
Effective PythonEffective Python
Effective Python
Β 
Understanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence FunctionsUnderstanding Blackbox Prediction via Influence Functions
Understanding Blackbox Prediction via Influence Functions
Β 
Attention Is All You Need
Attention Is All You NeedAttention Is All You Need
Attention Is All You Need
Β 
Attention
AttentionAttention
Attention
Β 
WWW 2020 XAI Tutorial Review
WWW 2020 XAI Tutorial ReviewWWW 2020 XAI Tutorial Review
WWW 2020 XAI Tutorial Review
Β 
Coding test review 2
Coding test review 2Coding test review 2
Coding test review 2
Β 
Locality sensitive hashing
Locality sensitive hashingLocality sensitive hashing
Locality sensitive hashing
Β 
Coding Test Review1
Coding Test Review1Coding Test Review1
Coding Test Review1
Β 
Strong convexity on gradient descent and newton's method
Strong convexity on gradient descent and newton's methodStrong convexity on gradient descent and newton's method
Strong convexity on gradient descent and newton's method
Β 

Recently uploaded

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
Β 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
Β 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
Β 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
Β 
πŸ’šTrustworthy Call Girls Pune Call Girls Service Just Call πŸ‘πŸ‘„6378878445 πŸ‘πŸ‘„ Top...
πŸ’šTrustworthy Call Girls Pune Call Girls Service Just Call πŸ‘πŸ‘„6378878445 πŸ‘πŸ‘„ Top...πŸ’šTrustworthy Call Girls Pune Call Girls Service Just Call πŸ‘πŸ‘„6378878445 πŸ‘πŸ‘„ Top...
πŸ’šTrustworthy Call Girls Pune Call Girls Service Just Call πŸ‘πŸ‘„6378878445 πŸ‘πŸ‘„ Top...vershagrag
Β 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptxrouholahahmadi9876
Β 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
Β 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
Β 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
Β 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
Β 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
Β 
Ghuma $ Russian Call Girls Ahmedabad β‚Ή7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad β‚Ή7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad β‚Ή7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad β‚Ή7.5k Pick Up & Drop With Cash Payment 8...gragchanchal546
Β 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...ppkakm
Β 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfsumitt6_25730773
Β 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementDr. Deepak Mudgal
Β 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
Β 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
Β 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
Β 

Recently uploaded (20)

COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
Β 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
Β 
Call Girls in South Ex (delhi) call me [πŸ”9953056974πŸ”] escort service 24X7
Call Girls in South Ex (delhi) call me [πŸ”9953056974πŸ”] escort service 24X7Call Girls in South Ex (delhi) call me [πŸ”9953056974πŸ”] escort service 24X7
Call Girls in South Ex (delhi) call me [πŸ”9953056974πŸ”] escort service 24X7
Β 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
Β 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
Β 
πŸ’šTrustworthy Call Girls Pune Call Girls Service Just Call πŸ‘πŸ‘„6378878445 πŸ‘πŸ‘„ Top...
πŸ’šTrustworthy Call Girls Pune Call Girls Service Just Call πŸ‘πŸ‘„6378878445 πŸ‘πŸ‘„ Top...πŸ’šTrustworthy Call Girls Pune Call Girls Service Just Call πŸ‘πŸ‘„6378878445 πŸ‘πŸ‘„ Top...
πŸ’šTrustworthy Call Girls Pune Call Girls Service Just Call πŸ‘πŸ‘„6378878445 πŸ‘πŸ‘„ Top...
Β 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
Β 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
Β 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Β 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
Β 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
Β 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
Β 
Ghuma $ Russian Call Girls Ahmedabad β‚Ή7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad β‚Ή7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad β‚Ή7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad β‚Ή7.5k Pick Up & Drop With Cash Payment 8...
Β 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
Β 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
Β 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
Β 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
Β 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
Β 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Β 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
Β 

Coding Test Review 3