SlideShare a Scribd company logo
Coding test review
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 review (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

Recently uploaded (20)

PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Geodesy 1.pptx...............................................
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
DOCX
573137875-Attendance-Management-System-original
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
web development for engineering and engineering
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Digital Logic Computer Design lecture notes
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
bas. eng. economics group 4 presentation 1.pptx
Lecture Notes Electrical Wiring System Components
Geodesy 1.pptx...............................................
Automation-in-Manufacturing-Chapter-Introduction.pdf
573137875-Attendance-Management-System-original
Foundation to blockchain - A guide to Blockchain Tech
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
web development for engineering and engineering
Embodied AI: Ushering in the Next Era of Intelligent Systems
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Internet of Things (IOT) - A guide to understanding
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
CYBER-CRIMES AND SECURITY A guide to understanding
OOP with Java - Java Introduction (Basics)
Digital Logic Computer Design lecture notes
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx

Coding test review