189. Rotate Array (Medium)
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example 1: Example 2: Solutions 1 : Solutions 2 : Solution 3:
Learn to Code and Code to Learn
Your Journey to Code Mastery
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example 1: Example 2: Solutions 1 : Solutions 2 : Solution 3:
Problem Given an array A[] of size N and a positive integer K, find the first negative integer for each and every window(contiguous subarray) of size K. Solution-1 Solution-2
Problem : Given an array of integers and a number K. Find the count of distinct elements in every window of size K in the array. Solution:
Day 1 Highlights: Introduction and History: Dive into the fascinating history of the C programming language and understand its evolution. Structure of C Programs: Learn the fundamental structure that every C program follows. Discover the key components that make up a C program. Setting Up Your Environment: Get your hands dirty by setting up a…
Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [-1,0,3,5,9,12], target = 9 Output: 4 Explanation: 9 exists in nums and its index is 4 Example…
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [1,3,5,6], target = 5 Output: 2 Example 2: Input:…
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad. Suppose you have n versions [1, 2, …, n] and you want to…
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1,2,3,1] Output: true Example 2: Input: nums = [1,2,3,4] Output: false Example 3: Input: nums = [1,1,1,3,3,4,3,2,4,2] Output: true Solution:
Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3,4] Example 2: Input: nums = [5,7,7,8,8,10], target = 6 Output: [-1,-1] Example…
Read More “#34 Find First and Last Position of Element in Sorted Array” »
Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s. A shift on s consists of moving the leftmost character of s to the rightmost position. For example, if s = “abcde”, then it will be “bcdea” after one shift. Example 1: Input: s = “abcde”, goal = “cdeab” Output: true Example 2: Input: s = “abcde”, goal = “abced” Output: false Solution…