Leetcode

Leetcode

Assessment

Assessment

Created by

Shawn Saunders

others

1 plays

Hard

Student preview

quiz-placeholder

80 questions

Show answers

1.

Open Ended

30 sec

1 pt

Trapping rain water problem

Evaluate responses using AI:

OFF

Answer explanation

traverse every array element and find the highest bars on left and right sides. Take the smaller of two heights. The difference between smaller height and height of current element is the amount of water that can be stored in this array element, MINUS the element height itself An Efficient Solution is to prre-compute highest bar on left and right of every bar in O(n) time. Then use these pre-computed values to find the amount of water in every array element. Below is C++ implementation of this solution. O(1) Space: move in from both sides, keep highest left and highest right as 2 variables keep going till left index is bigger than right index (lo <= hi) we will calculate water trapped on smaller element out of A[lo] and A[hi] first and move the pointers till lo doesn't cross hi. you pick the smaller of the 2 because if the right max is zero, doesnt matter that left has water (cant be held in)

2.

Open Ended

30 sec

1 pt

Repeated String Match Given two strings A and B, find the minimum number of times A has to be repeated such that B is a substring of it. If no such solution, return -1. For example, with A = "abcd" and B = "cdabcdab". Return 3, because by repeating A three times ("abcdabcdabcd"), B is a substring of it; and B is not a substring of A repeated two times ("abcdabcd").

Evaluate responses using AI:

OFF

Answer explanation

Reworded: What is the smallest k such that B is a substring of A*k Find the smallest q for which len(A*q) >= len(B) Now try q and then q+1 Why up to q+1? that q+1 gives A enough repeated length to try every starting combination to fit B into eg. if A = ABC and B = CABCA, in this case ABCABC is not enough since in this case, B starts with the last letter of the pattern, but adding one more: ABCABCABC allows the CABCA to appear BETTER SOLUTION: Use Rabin-Karp algorithm

3.

Open Ended

30 sec

1 pt

Rabin-Karp Algorithm

Evaluate responses using AI:

OFF

Answer explanation

String searching algorithm uses hashing to find any one of a set of pattern strings in a text. For text of length n and p patterns of combined length m, its average and best case running time is O(n+m) in space O(p), but its worst-case time is O(nm).

4.

Open Ended

30 sec

1 pt

Find a pattern of length M in a search string of length N (usually N >> M)

Evaluate responses using AI:

OFF

Answer explanation

Use rabin-karp using rolling hash comparison by doing modulo of a prime number

5.

Open Ended

30 sec

1 pt

Height of a binary tree

Evaluate responses using AI:

OFF

Answer explanation

The height of a binary tree is the number of edges between the tree's root and its furthest leaf. This means that a tree containing a single node has a height of 0.

6.

Open Ended

30 sec

1 pt

Binary search tree

Evaluate responses using AI:

OFF

Answer explanation

binary tree in which the value of each parent node's left child is less than the value the parent node, and the value of the parent node is less than the value of its right child.

cartoon woman

Explore this activity with a free account

Find a similar activity

Create activity tailored to your needs using

Quizizz AI
TERM TEST - FEEDBACK AND CONTROL SYSTEM

75 questions

TERM TEST - FEEDBACK AND CONTROL SYSTEM

assessment

DAA -1

79 questions

DAA -1

assessment

DAA -1

79 questions

DAA -1

assessment

Game Design Semester 1 Test Review

75 questions

Game Design Semester 1 Test Review

assessment

test2

75 questions

test2

assessment

PRf192

80 questions

PRf192

assessment

тест

79 questions

тест

assessment

Unit 4 exam

75 questions

Unit 4 exam

assessment