Pergunta da entrevista

Entrevista para Full Stack Developer

-

Panaya

return true if array of size n contains a permutation of [1,n]

Resposta

Respostas da entrevista

5 respostas

0

for(var i=0; i

Dudi 2 em

0

public static bool isPermutation(int[] arr) { int num = 0; for (int i = 0; i arr.Length) return false;//number out of range int tmp = 1 << (arr[i]-1); if ((num & tmp) == tmp) return false;// number was found before - duplicate num |= tmp; } return true; }

Rinat em

0

// Java Program to decide if an // array represents a permutation or not import java.util.*; class GFG{ // Function to check if an // array represents a permutation or not static boolean permutation(int []arr, int n) { // Set to check the count // of non-repeating elements Set hash = new HashSet(); int maxEle = 0; for (int i = 0; i < n; i++) { // Insert all elements in the set hash.add(arr[i]); // Calculating the max element maxEle = Math.max(maxEle, arr[i]); } if (maxEle != n) return false; // Check if set size is equal to n if (hash.size() == n) return true; return false; } // Driver code public static void main(String args[]) { int arr[] = { 1, 2, 5, 3, 2 }; int n = arr.length; if (permutation(arr, n)) System.out.println("Yes"); else System.out.println("No"); } }

Shubham chinchure em

0

var permotation = function(arrayOriginal, arrayDuplication){ if(!Array.isArray(arrayOriginal) || !Array.isArray(arrayDuplication) || arrayOriginal.length != arrayDuplication.length){ return false; } var dictionaryObj = {}; var sumDuplication = 0; for(var i=0; i

Dudi em

0

var permotation = function(arrayOriginal, arrayDuplication){ if(!Array.isArray(arrayOriginal) || !Array.isArray(arrayDuplication) || arrayOriginal.length != arrayDuplication.length){ return false; } var dictionaryObj = {}; var sumDuplication = 0;

Dudi 1 em

Adicionar respostas ou comentários

Para comentar sobre isso, entre na conta ou cadastre-se.