SlideShare a Scribd company logo
Coding test review2
Facebook – Coding Interview (20mins)
Q.
You have a sorted array of integers. Write a
function that returns a sorted array containing
the squares of those integers.
Examples)
[-7, -3, -1, 4, 8, 12] -> [1, 9, 16, 49, 64, 144]
𝑂(𝑛𝑙𝑜𝑔𝑛) 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛
class Solution:
def sortedsquared(self, arrays):
for idx, num in enumerate(arrays):
arrays[idx] = num**2
return sorted(arrays)
𝑂(𝑛) 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛
class Solution:
def sortedsquared(self, arrays):
ans = [0]*len(arrays)
count = 0
while len(arrays) != 0:
if abs(arrays[0]) >= abs(arrays[-1]):
ans[-count-1] = arrays.pop(0)**2
else:
ans[-count-1] = arrays.pop(-1) ** 2
count += 1
return ans
Google – Coding Interview (15mins)
Q.
You have a two integer arrays, a and b, and an integer
target value v. Determine whether there is a pair of
numbers, where one number is taken from a and the other
from b, that can be added together to get a sum of v.
Return True if such a pair exists, otherwise return False.
Examples)
a = [0, 0, -5]
b = [-10, 40, -3, 9]
v = -8
True
𝑂(𝑛2
) 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛
class Solution:
def sumofTwo(self, a, b, v):
for a_num in a:
for b_num in b:
if a_num + b_num == v:
return True
return False
𝑂(𝑛) 𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛
class Solution:
def sumofTwo(self, a, b, v):
d = {}
for a_num in a:
d[v - a_num] = True
for b_num in b:
if b_num in d:
return True
return False
Thank You

More Related Content

PPTX
Chapter 7.2
PDF
Numpy tutorial(final) 20160303
PDF
Numpy python cheat_sheet
PDF
Python matplotlib cheat_sheet
PDF
Coding Test Review1
PPT
PDF
Pandas pythonfordatascience
PDF
Coding test review 2
Chapter 7.2
Numpy tutorial(final) 20160303
Numpy python cheat_sheet
Python matplotlib cheat_sheet
Coding Test Review1
Pandas pythonfordatascience
Coding test review 2

What's hot (18)

PPT
Piecewise functions updated_2016
PDF
11 1. multi-dimensional array eng
PPTX
Statistics - ArgMax Equation
PDF
Advanced matlab codigos matematicos
PDF
NumPy Refresher
PPT
Gr10 piecewise functions
PPTX
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
PPT
Multi dimensional arrays
PDF
Introduction to Machine Learning
PDF
Bioalgo 2013-07-alignment-2
PPTX
Python data structures
PDF
Cheat Sheet for Machine Learning in Python: Scikit-learn
PPTX
MATLAB - Arrays and Matrices
PPTX
Piecewise functions
PPT
2.7 Piecewise Functions
PDF
09 a1bs04 mathematical methods
PDF
Pandas Cheat Sheet
PPT
Arrays
Piecewise functions updated_2016
11 1. multi-dimensional array eng
Statistics - ArgMax Equation
Advanced matlab codigos matematicos
NumPy Refresher
Gr10 piecewise functions
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
Multi dimensional arrays
Introduction to Machine Learning
Bioalgo 2013-07-alignment-2
Python data structures
Cheat Sheet for Machine Learning in Python: Scikit-learn
MATLAB - Arrays and Matrices
Piecewise functions
2.7 Piecewise Functions
09 a1bs04 mathematical methods
Pandas Cheat Sheet
Arrays
Ad

Similar to Coding test review2 (20)

PDF
Numpy python cheat_sheet
PDF
Python_cheatsheet_numpy.pdf
PPTX
NUMPY LIBRARY study materials PPT 2.pptx
PDF
An overview of Python 2.7
PDF
A tour of Python
PPT
14078956.ppt
PDF
Master the arrays and algorithms using Algotutor
PPT
Topic20Arrays_Part2.ppt
PDF
Python programming : Arrays
PPTX
Lecture_3.5-Array_Type Conversion_Math Class.pptx
PPTX
2.Exploration with CAS-I.Lab2.pptx
PPTX
ARRAY OPERATIONS.pptx
PDF
Unit-5-Part1 Array in Python programming.pdf
PDF
Introduction to NumPy
PDF
Introduction to NumPy (PyData SV 2013)
PDF
Arrays in python
PPT
ECCV2010: feature learning for image classification, part 2
PPTX
NumPy_Broadcasting Data Science - Python.pptx
PPT
Introduction to MATLAB
PPTX
Python programming workshop session 3
Numpy python cheat_sheet
Python_cheatsheet_numpy.pdf
NUMPY LIBRARY study materials PPT 2.pptx
An overview of Python 2.7
A tour of Python
14078956.ppt
Master the arrays and algorithms using Algotutor
Topic20Arrays_Part2.ppt
Python programming : Arrays
Lecture_3.5-Array_Type Conversion_Math Class.pptx
2.Exploration with CAS-I.Lab2.pptx
ARRAY OPERATIONS.pptx
Unit-5-Part1 Array in Python programming.pdf
Introduction to NumPy
Introduction to NumPy (PyData SV 2013)
Arrays in python
ECCV2010: feature learning for image classification, part 2
NumPy_Broadcasting Data Science - Python.pptx
Introduction to MATLAB
Python programming workshop session 3
Ad

More from SEMINARGROOT (20)

PDF
Metric based meta_learning
PDF
Sampling method : MCMC
PDF
Demystifying Neural Style Transfer
PDF
Towards Deep Learning Models Resistant to Adversarial Attacks.
PDF
The ways of node embedding
PDF
Graph Convolutional Network
PDF
Denoising With Frequency Domain
PDF
Bayesian Statistics
PDF
Coding Test Review 3
PDF
Time Series Analysis - ARMA
PDF
Differential Geometry for Machine Learning
PDF
Generative models : VAE and GAN
PDF
Effective Python
PDF
Understanding Blackbox Prediction via Influence Functions
PDF
Attention Is All You Need
PDF
Attention
PDF
WWW 2020 XAI Tutorial Review
PDF
Locality sensitive hashing
PDF
Strong convexity on gradient descent and newton's method
PDF
SVM (Support Vector Machine & Kernel)
Metric based meta_learning
Sampling method : MCMC
Demystifying Neural Style Transfer
Towards Deep Learning Models Resistant to Adversarial Attacks.
The ways of node embedding
Graph Convolutional Network
Denoising With Frequency Domain
Bayesian Statistics
Coding Test Review 3
Time Series Analysis - ARMA
Differential Geometry for Machine Learning
Generative models : VAE and GAN
Effective Python
Understanding Blackbox Prediction via Influence Functions
Attention Is All You Need
Attention
WWW 2020 XAI Tutorial Review
Locality sensitive hashing
Strong convexity on gradient descent and newton's method
SVM (Support Vector Machine & Kernel)

Recently uploaded (20)

PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Welding lecture in detail for understanding
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
web development for engineering and engineering
PDF
Well-logging-methods_new................
PPTX
Sustainable Sites - Green Building Construction
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
OOP with Java - Java Introduction (Basics)
Welding lecture in detail for understanding
CH1 Production IntroductoryConcepts.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
bas. eng. economics group 4 presentation 1.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Automation-in-Manufacturing-Chapter-Introduction.pdf
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Foundation to blockchain - A guide to Blockchain Tech
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
web development for engineering and engineering
Well-logging-methods_new................
Sustainable Sites - Green Building Construction
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...

Coding test review2