L3 Assessment - Dictionary Data Structure

Problem 1

Use your own words, explain what is a dictionary data structure.

Problem 2

Can a key in a dictionary have duplicates?

Problem 3

What is the time complexity of accessing a key and its paired value in a dictionary?

Problem 4

Write an if else statement that check if the key "cherry" exist in the dictionary.

Problem 5

Write a program that stores all keys in a dictionary into a list.

Example:

Problem 6

Write a program that flips the keys and its associated values. You can assume there will be no duplicate values.

Example:

Problem 7

Leetcode: Two Sum

Given a list of integers

nums
and an integer
target
, find the indices of the two integers that adds up to
target
.

Your solution has to have a linear time complexity

O(n)
.

Problem 8

Leetcode: Contains Duplicate

Given a list of integers

nums
, check if there are any values that appears more than twice.

Your solution has to have a linear time complexity

O(n)
, and need to use the dictionary data structure.

Problem 9

Leetcode: Find the Difference

Given two stings

s1
and
s2
, string
s2
is generated by random shuffling string
s1
and then add one more character at a random position.

Find the letter that was added to

s2
.