1920. Build Array from Permutation
Easy
2.2K
240
Companies
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.
A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).
Example 1:
Input: nums = [0,2,1,5,3,4]
Output: [0,1,2,4,5,3]
Explanation: The array ans is built as follows:
ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
= [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]
= [0,1,2,4,5,3]
Example 2:
Input: nums = [5,0,1,2,3,4]
Output: [4,5,0,1,2,3]
Explanation: The array ans is built as follows:
ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
= [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]
= [4,5,0,1,2,3]
Constraints:
1 <= nums.length <= 1000
0 <= nums[i] < nums.length
The elements in nums are distinct.
Easy
2.2K
240
Companies
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it.
A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusive).
Example 1:
Input: nums = [0,2,1,5,3,4]
Output: [0,1,2,4,5,3]
Explanation: The array ans is built as follows:
ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
= [nums[0], nums[2], nums[1], nums[5], nums[3], nums[4]]
= [0,1,2,4,5,3]
Example 2:
Input: nums = [5,0,1,2,3,4]
Output: [4,5,0,1,2,3]
Explanation: The array ans is built as follows:
ans = [nums[nums[0]], nums[nums[1]], nums[nums[2]], nums[nums[3]], nums[nums[4]], nums[nums[5]]]
= [nums[5], nums[0], nums[1], nums[2], nums[3], nums[4]]
= [4,5,0,1,2,3]
Constraints:
1 <= nums.length <= 1000
0 <= nums[i] < nums.length
The elements in nums are distinct.
waylonworldwebdesignerspvtltd@gmail.com
Can send your resumes here
Location:- banglore
Salary range 15-35k
Requirements FullStack developer
Mass HIRING startup culture new technologies to learn and
Greetings Waylon World web designers,
We are looking for fullstack mobile application developers with experience,
Skills required any of the following:
1) Kotlin
2) Flutter
3) React native
4) Angularjs
5) Node
6) Laravel php
7) AWS , other servers
8) Mysql
9) xcode
please feel free to call or message us.
Thank you
Projects for java , React-Js, react next, and many more they have
Can send your resumes here
Location:- banglore
Salary range 15-35k
Requirements FullStack developer
Mass HIRING startup culture new technologies to learn and
Greetings Waylon World web designers,
We are looking for fullstack mobile application developers with experience,
Skills required any of the following:
1) Kotlin
2) Flutter
3) React native
4) Angularjs
5) Node
6) Laravel php
7) AWS , other servers
8) Mysql
9) xcode
please feel free to call or message us.
Thank you
Projects for java , React-Js, react next, and many more they have
Available for immediate joiners let me know once you send resumes we will try to manage for your job
In call with some more organization let me confirm then will do share details if it's a mass Hiring
If you aren't able to mail from Outlook kindly use Gmail it will be done if still not do please share your resumes @stockkida for further process
https://leetcode.com/problems/delete-columns-to-make-sorted/solutions/2994000/answer-with-streamapi-java/
That's why command on streams n Java8 is must needed for now
That's why command on streams n Java8 is must needed for now
LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Forwarded from Aman Raj
Alice is still not satisfied with Bob's math skills so she gave him a new challenge.
Given a positive integer NN, find any 33 distinct positive integers A, B, CA,B,C such that:
The product of any two of these 33 integers is a divisor of NN.
The product of all three integers is a multiple of NN.
If multiple solutions exist, you may print any of them.
Print -1−1 if no solution exists.
Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
The first and only line of each test case contains a single integer, NN.
Output Format
For each test case, output on a new line three space-separated integers satisfying the given condition.
Print -1−1 if the answer does not exist.
Constraints
1 \leq T \leq 1001≤T≤100
1 \leq N \leq 10^91≤N≤10
9
Given a positive integer NN, find any 33 distinct positive integers A, B, CA,B,C such that:
The product of any two of these 33 integers is a divisor of NN.
The product of all three integers is a multiple of NN.
If multiple solutions exist, you may print any of them.
Print -1−1 if no solution exists.
Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
The first and only line of each test case contains a single integer, NN.
Output Format
For each test case, output on a new line three space-separated integers satisfying the given condition.
Print -1−1 if the answer does not exist.
Constraints
1 \leq T \leq 1001≤T≤100
1 \leq N \leq 10^91≤N≤10
9
Forwarded from Aman Raj
Rushitote went to a programming contest to distribute apples and oranges to the contestants.
He has NN apples and MM oranges, which need to be divided equally amongst the contestants. Find the maximum possible number of contestants such that:
Every contestant gets an equal number of apples; and
Every contestant gets an equal number of oranges.
Note that every fruit with Rushitote must be distributed, there cannot be any left over.
For example, 22 apples and 44 oranges can be distributed equally to two contestants, where each one receives 11 apple and 22 oranges.
However, 22 apples and 55 oranges can only be distributed equally to one contestant.
Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
The first and only line of each test case contains two space-separated integers NN and MM — the number of apples and oranges, respectively.
Output Format
For each test case, output on a new line the answer: the maximum number of contestants such that everyone receives an equal number of apples and an equal number of oranges.
Constraints
1 \leq T \leq 10001≤T≤1000
1 \leq N , M \leq 10^91≤N,M≤10
9
He has NN apples and MM oranges, which need to be divided equally amongst the contestants. Find the maximum possible number of contestants such that:
Every contestant gets an equal number of apples; and
Every contestant gets an equal number of oranges.
Note that every fruit with Rushitote must be distributed, there cannot be any left over.
For example, 22 apples and 44 oranges can be distributed equally to two contestants, where each one receives 11 apple and 22 oranges.
However, 22 apples and 55 oranges can only be distributed equally to one contestant.
Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
The first and only line of each test case contains two space-separated integers NN and MM — the number of apples and oranges, respectively.
Output Format
For each test case, output on a new line the answer: the maximum number of contestants such that everyone receives an equal number of apples and an equal number of oranges.
Constraints
1 \leq T \leq 10001≤T≤1000
1 \leq N , M \leq 10^91≤N,M≤10
9
Forwarded from Aman Raj
Alice gave Bob 33 integers N, K,N,K, and SS. Help Bob find an SS-good sequence.
A sequence BB of length NN is called SS-good if the following conditions are met:
B_i \in \{-1, 0, 1\}B
i
​
∈{−1,0,1} for each 1 \leq i \leq N1≤i≤N
\sum_{i=1}^N B_i\cdot K^{i-1} = S∑
i=1
N
​
B
i
​
â‹…K
i−1
=S
If there are multiple SS-good sequences, print any of them.
If no SS-good sequence exists, print -2−2.
Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
Each test case consists of a single line of input containing three space-separated integers — N, K,N,K, and SS.
Output Format
For each test case:
If no SS-good sequence exists, print -2−2.
Otherwise, output NN space-separated integers denoting the SS-good sequence.
If multiple SS-good sequences exist, you may print any of them.
Constraints
1 \leq T \leq 10^41≤T≤10
4
1 \leq N \leq 1001≤N≤100
2 \leq K \leq 1002≤K≤100
1 \leq S \leq 10^{18}1≤S≤10
18
A sequence BB of length NN is called SS-good if the following conditions are met:
B_i \in \{-1, 0, 1\}B
i
​
∈{−1,0,1} for each 1 \leq i \leq N1≤i≤N
\sum_{i=1}^N B_i\cdot K^{i-1} = S∑
i=1
N
​
B
i
​
â‹…K
i−1
=S
If there are multiple SS-good sequences, print any of them.
If no SS-good sequence exists, print -2−2.
Input Format
The first line of input will contain a single integer TT, denoting the number of test cases.
Each test case consists of a single line of input containing three space-separated integers — N, K,N,K, and SS.
Output Format
For each test case:
If no SS-good sequence exists, print -2−2.
Otherwise, output NN space-separated integers denoting the SS-good sequence.
If multiple SS-good sequences exist, you may print any of them.
Constraints
1 \leq T \leq 10^41≤T≤10
4
1 \leq N \leq 1001≤N≤100
2 \leq K \leq 1002≤K≤100
1 \leq S \leq 10^{18}1≤S≤10
18