Original link:http://www.careercup.com/question?id=12708671
You are given an unsorted array with both positive and negative elements. You have to find the smallest positive number missing from the array in O(n) time using constant extra space.
Eg:
Input = {2, 3, 7, 6, 8, -1, -10, 15}
Output = 1
Input = { 2, 3, -7, 6, 8, 1, -10, 15 }
Output = 4
You are given an unsorted array with both positive and negative elements. You have to find the smallest positive number missing from the array in O(n) time using constant extra space.
Eg:
Input = {2, 3, 7, 6, 8, -1, -10, 15}
Output = 1
Input = { 2, 3, -7, 6, 8, 1, -10, 15 }
Output = 4
Solution:
1.) Partition the array into the values smaller than zero and +ve integers using the Quicksort partition method. This can be done in O(n) time and in the same array.
2.) Now you the index of element '0' or first +ve number, say this is idxZ.
3.) Traverse starting from idxZ and set the sign bit of the value at position (idxZ + A[idxZ]) to 1. You do this only in case the value of position lies in the bounds of array.
4.) Now starting at 'idxZ' find the first position where the sign bit is UNSET. This gives you the number you are looking for.
I have read your blog very useful information to everyone.Thanks for sharing and keep updating more.
ReplyDeleteWeb Designing Training in Chennai
Web Designing Course in Chennai
Web Designing Training in Bangalore
Web Designing Course in Bangalore
Web Designing Training in Hyderabad
Web Designing Course in Hyderabad
Web Designing Training in Coimbatore
Web Designing Training
Web Designing Online Training
https://bayanlarsitesi.com/
ReplyDeleteKayseri
Sinop
Kilis
Hakkari
İU7Z
Antalya
ReplyDeleteTrabzon
Niğde
Maraş
Antep
P81M
Muğla
ReplyDeleteBitlis
Karaman
CV2HU
Isparta
ReplyDeleteTunceli
Yozgat
Çorum
Konya
5A6İT
Ağrı
ReplyDeleteDiyarbakır
Bolu
Elazığ
Siirt
D4NBL
Bursa
ReplyDeleteKırşehir
Muş
Mersin
Çanakkale
UNY
Burdur
ReplyDeleteGiresun
Sakarya
Artvin
Mardin
24TM
Samsun
ReplyDeleteNevşehir
Van
Bartın
Edirne
LO33O
İstanbul
ReplyDeleteSivas
Kırıkkale
Zonguldak
Iğdır
KTT0
Yalova
ReplyDeleteHatay
Muş
Bursa
Mersin
LZM8
ankara
ReplyDeletesakarya
tekirdağ
kastamonu
amasya
C046NG
Kastamonu Lojistik
ReplyDeleteYozgat Lojistik
Çorlu Lojistik
Kırşehir Lojistik
Sinop Lojistik
K1NK
00306
ReplyDeletesohbet uygulamaları
bingöl bedava görüntülü sohbet sitesi
maraş en iyi ücretsiz sohbet siteleri
karabük canlı sohbet sitesi
bayburt parasız sohbet siteleri
parasız sohbet
bingöl sohbet siteleri
antalya ücretsiz sohbet
düzce rastgele görüntülü sohbet uygulamaları