Skip to content

Instantly share code, notes, and snippets.

@Youngestdev
Created July 11, 2020 18:51
Show Gist options
  • Select an option

  • Save Youngestdev/165cd67719168e47522237e3551c2892 to your computer and use it in GitHub Desktop.

Select an option

Save Youngestdev/165cd67719168e47522237e3551c2892 to your computer and use it in GitHub Desktop.
Second joint session.

In today's session, we'd chill and vibe as usual over a couple of questions. Some of the questions will be in this Gist and we might choose some randomly from LeetCode. The questions are listed below, answers will be posted here subsequently.

Question 1

Write a program that takes an array A and an index i rnto A, and rearranges the elements such that all elements less than A[r] (the "pivot") appear first, followed by elements equal to the pivot, followed by elements greater than the pivot. You are expected to have a function solution(array, index)

Example:

input: array = [0,1,2,0,2,1,1], index = 3
output: [0,0,1,2,2,1,1]

input: [0,1,0,1,1,2,2], index = 2
output: [0,0,1,1,1,2,2]

input: array = [-3, 0, -1, 1, 1, 4, 2], index = 2
output: [-3,-1,0,1,1,2,4]

Question 2

Given an array A of n objects with Boolean-valued keys, reorder the array so that objects that have tje key false appear first. The relative ordering of objects with key true should not change. Use O(1) additional space and O(n) time.

Example:

input: array = [{'first': True}, {'second': False}, {'third': False}, {'fourth': True}, {'fifth': True}]
output: [{'second': False}, {'Third': False}, {'first': True}, {'fourth': True}, {'fifth': True}]
@Youngestdev
Copy link
Copy Markdown
Author

Hm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment