Python Problem Practice I

We are not concerned about the time or space complexity here. We are more interest in finding a solution, however inefficient the solution may be.

Find an index of number d in array arr

  • Example 1:

    • Input: arr = [4,2,6,8,16,2,40,51], d = 16

    • Output: 4

  • Example 2:

    • Input: arr = [6,12,73,31,74,41], d = 91

    • Output = -1

Find largest element index in list arr

  • Example 1:

    • Input: arr = [4,2,6,8,16,2,40,51]

    • Output: 51

  • Example 2:

    • Input: arr = [6,12,73,31,74,41]

    • Output: 74

Write a program to print all 13 divisible numbers between n1 and n2

  • Example 1:

    • Input: n1 = 30, n2 = 321

    • Output:

  • Example 2:

    • Input: n1 = 135, n2 = 1035

    • Output:

Write a function called fizz_buzz that takes a number

  • If the number is divisible by 3, it should return “Fizz”.

  • If it is divisible by 5, it should return “Buzz”.

  • If it is divisible by both 3 and 5, it should return “FizzBuzz”.

Otherwise, it should return the same number.

Write a function that prints all the prime numbers between 0 and n

where n is an integer

Find peak element from an array

A peak element is an element that is strictly greater than its neighbors.

Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.

You may imagine that nums[-1] = nums[n] = -∞.

Example 1:

Input: nums = [1,2,3,1] Output: 2 Explanation: 3 is a peak element and your function should return the index number 2.

Example 2:

Input: nums = [1,2,1,3,5,6,4] Output: 1 or 5

You can walk back and forth between rooms freely. Return true if and only if you can enter every room

There are N rooms and you start in room 0. Each room has a distinct number in 0, 1, 2, ..., N-1, and each room may have some keys to access the next room.

Formally, each room i has a list of keys rooms[i], and each key rooms[i][j] is an integer in [0, 1, ..., N-1] where N = rooms.length. A key rooms[i][j] = v opens the room with number v.

Initially, all the rooms start locked (except for room 0).

Example 1:

Input: [[1],[2],[3],[]] Output: true Explanation: We start in room 0, and pick up key 1. We then go to room 1, and pick up key 2. We then go to room 2, and pick up key 3. We then go to room 3. Since we were able to go to every room, we return true. Example 2:

Input: [[1,3],[3,0,1],[2],[0]] Output: false Explanation: We can't enter the room with number 2.

Reference for More Questions

For basic problems, here you can find problems topicwise

InterviewBit

Hackerank: Basics and Others

LeetCode: 30 Days 30 Problems Challenge and Others

Here 30-day challenge, 30 problems for 30 days, from basics to a decent level. Start here

Last updated

Was this helpful?