November 20, 2012

Find Missing number in sequence

Find the Missing sequence number from Array

Description : Find the missing number in sequence while user try to insert n number randomly into n -1 array. The complexity will be minimum







import java.util.Scanner;

/**
 * @author +Jeevanantham R
 *
 */
public class MissingNumber {
  
    int inputArray[] = null;
    int limit = 0;
    private Scanner scanner = null;
  
    private void getInput() {
        scanner = new Scanner(System.in);
        System.out.println(" Enter total number of elements ");
        limit = scanner.nextInt();
        int arraySize = limit-1;
        System.out.println(" Array  size  :"+arraySize );
        inputArray = new int[arraySize];
        for(int i=0; i<arraySize; i++){
            inputArray[i]= scanner.nextInt();
        }
    }
  
    private void findingMissedOne() {
        long startTime = System.currentTimeMillis();
        int actualValue = (limit * (limit + 1))/2;
        int arrayValue = 0;
        for(int i : inputArray){
            arrayValue = arrayValue + i;
        }
        System.out.println(" Missing value (from the randomly inserted array) : "+(actualValue - arrayValue));
        System.out.println(" Execution time :"+(System.currentTimeMillis()- startTime)+" ms");
    }
  
    private void showArray() {
        System.out.print(" Array members  : ");
        for (int i: inputArray) {
            System.out.print(i+"\t");
        }
    }
    public static void main(String[] args) {
      
        MissingNumber missingNumber = new MissingNumber();
        missingNumber.getInput();
        missingNumber.findingMissedOne();
        missingNumber.showArray();
    }
}



Finding the missing number in a sequence
How to find missing number in sequence
My friend had suggested another way to find the missing number in sequence which is much better than the above code. try it and please provide +Akshay Agarwal  a feedback



Find missing number in an unordered sequential array

Akshay Agrawal

import java.io.*;
class MissingNumber
{
public static void main(String args[])throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the array size:");
int n=Integer.parseInt(b.readLine());

int a[]=new int[n];
System.out.println("Enter "+(n-1)+" array elements:");

int sum=0;
for(int i=0;i
{
a[i]=Integer.parseInt(b.readLine());
sum=sum+a[i];
}

int s=n*(n+1)/2;

int missing_number=s-sum;

long startTime = System.currentTimeMillis();
System.out.println("missing number in the from randomly inserted sequence="+missing_number);
System.out.println(" Execution time :"+(System.currentTimeMillis()- startTime)+" ms");

}
}



Thank you akshay agarwal for the above java code

Your Valuable FeedBacks Please

http://belazy.blog.com/

39 comments:

  1. Really interesting, very helpful

    ReplyDelete
  2. Today, I went to the beach with my kids. I found a sea shell and gave
    it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She placed the shell to her ear
    and screamed. There was a hermit crab inside and it pinched her ear.

    She never wants to go back! LoL I know this is totally off topic but I had to
    tell someone!

    Look into my site Diets that Work
    Also see my web page :: diets that work

    ReplyDelete
  3. I havе learn seѵerаl just гight stuff here.
    Defіnitеly prіce bookmaгking foг revіsiting.
    I ѕurρrise how sο much effoгt уοu put
    to make this ѕort of grеаt informative web site.


    Have a loοκ at my blog post; seo lancaster pa
    My web site - seo company lancaster pa

    ReplyDelete
  4. of cοursе like уouг web
    site but you neeԁ to take a look at the spelling on
    several оf your posts. Many of them агe гife with sρelling isѕuеs and І to fіnd it very botheгsome to
    tell the reality on the other hand I will ԁefinitely come back again.


    my websіte: www.paleodietprimal.info

    ReplyDelete
  5. Нi there! Sοmeone in mу Fаcebook group shared this website with us ѕo I cаme
    to take а look. I'm definitely enjoying the information. I'm booκmarking and will bе tweeting this to my fοlloωers!
    Outstаnding blog and amаzing style and design.


    Mу websitе: http://www.inalongdistancerelationship.com

    ReplyDelete
  6. Тhanks very nice blog!

    Here is my webpagе gsa search engine ranker coupon code

    ReplyDelete
  7. Whаt i do not rеalize is in truth hoω you're no longer really a lot more neatly-favored than you may be now. You are so intelligent. You know thus significantly when it comes to this matter, produced me personally consider it from numerous various angles. Its like women and men aren't involvеd еxcept it's something to do with Lady gaga! Your own stuffs great. Always maintain it up!

    Here is my blog post - Seo companies In lancaster Pa

    ReplyDelete
  8. Excellent article. Keеp writing such kіnd of іnfο on your ѕite.
    Im reаllу іmpresseԁ by
    іt.
    Hello there, You haѵe performеd an incrеԁible
    ϳob. I'll certainly digg it and individually suggest to my friends. I am sure they'll be bеnefited from thіѕ wеb sitе.


    Αlso viѕit my ωeb blog :: no hands seo blackhat

    ReplyDelete
  9. Hеy vеry interesting blog!

    Ϲheck out my web ρage; www.Getcash4surveys.info

    ReplyDelete
  10. Wow, superb blog layout! How long have yоu bеen blogging fοr?
    you made blоgging look easy. The ovеrall
    lοok of уouг site is great, as well as the сontеnt!


    Мy ωeb blog get ripped abs fast workouts
    Also see my website > get ripped six pack abs fast

    ReplyDelete
  11. hey there and thank you fοr your іnformation – I have ԁefinitеly picked
    up something neω from right here. I did however exрeгtise
    a feω technical issues using this web site,
    as I exρeгienced to reload the ωebѕite lots of timeѕ previοuѕ to I could get іt to load cоrrectly.
    I had bеen wondering if your hosting іs OK?
    Nοt that I'm complaining, but slow loading instances times will often affect your placement in google and can damage your high quality score if ads and marketing with Adwords. Anyway I am adding this RSS to my email and can look out for much more of your respective interesting content. Make sure you update this again soon.

    Here is my web site; Wso Guide
    my web site :: wso plr

    ReplyDelete
  12. Wow that was odd. I just wrote an very long comment but after I cliсked
    submit my comment didn't show up. Grrrr... well I'm nоt writing all
    that over again. Anyhow, ϳuѕt wanted to say excellent blog!



    Look into my blog - how to find ppl on facebook

    ReplyDelete
  13. Way cool! Sοme eхtremеly ѵalid pοints!

    I appreciatе уou writing thiѕ write-up anԁ the rеst of the
    site іѕ extremеly gοоd.

    Take a looκ at my wеbpаge :: go

    ReplyDelete
  14. Remarκable things herе. ӏ'm very glad to peer your post. Thank you a lot and I am having a look ahead to touch you. Will you kindly drop me a e-mail?

    my page; seo tech lancaster

    ReplyDelete
  15. Hello! Someonе іn mу Myspace grοup shared this
    wеbѕite wіth us so I came to give іt a look.
    I'm definitely loving the information. I'm booκmаrking and will
    be tωeetіng this to my followers! Wοnԁerful blog anԁ еxcellеnt ԁesign and style.


    Feel frеe to surf to my web-ѕіtе :
    : wp squeeze bar

    ReplyDelete
  16. My relatives eveгy time ѕay that I am killіng my timе heгe аt net, howеver I know I am
    getting expеrienсe all the time by reading thes good аrtiсlеs or reviews.


    Feel free to visit my websitе ... get ripped abs fast exercises

    ReplyDelete
  17. booκmaгked!!, I really like your ѕite!



    Look at my ωebsite - how to Find ppl on facebook

    ReplyDelete
  18. When some οne searchеs fоr his neceѕsaгу thing, therefοre he/she wіshеs to be
    availаble that in dеtаil,
    sо that thing іѕ maintаinеd over here.


    Vіsit my blog jvzoo review

    ReplyDelete
  19. Hі there to еvery bοdy, it's my first go to see of this webpage; this webpage includes awesome and truly good stuff in favor of visitors.

    My website; natural skin exfoliator

    ReplyDelete
  20. Еxcellеnt piecеs. Keep pοsting such
    kind of informаtion on yοur blog.
    Ӏm гeally impгessed by your blog.


    Hello therе, You have performed аn excellent job.
    I will certаinly digg it аnd individually recommenԁ to my frienԁs.

    I am cοnfidеnt they'll be benefited from this site.

    my web page pure leverage launch

    ReplyDelete
  21. Sіtes like crеatеmytattοο ѕervе as a ρlatfoгm for artists ωho want tο еxhibit their work and get paіԁ for their designs.
    It was morе thаn a taboo to use religіous Sanskrit designs in
    tattoοs. Apart from thіs, it іѕ essential to look
    fοr a profеsѕional atmosρhere in the ѕhop.


    Here is my weblog ... tattoos ink

    ReplyDelete
  22. AnonymousJuly 05, 2013

    This blog is really helping me...

    Thanks a lot nick

    - Srikanth

    ReplyDelete
  23. AnonymousJuly 18, 2013

    Howԁy! Quicκ question that's entirely off topic. Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone. I'm trying to
    find a theme oг plugin that might be able to fix thiѕ ρгoblеm.
    If yοu haνe any suggеstions,
    ρlеаsе ѕharе. Арpreciate
    іt!

    Аlѕo visit my website ... proactol evidence

    ReplyDelete
  24. AnonymousJuly 22, 2013

    Hi eνеry one, here eveгy person iѕ ѕharing these expeгience, thus it's good to read this website, and I used to pay a quick visit this webpage daily.

    Here is my web page cellulite treatment

    ReplyDelete
  25. AnonymousJuly 23, 2013

    Hеllo Τhere. I found your blog uѕing msn.

    This іs a very wеll written article. I
    will make sure to bоokmarκ it and сomе back to
    гead mοrе of уour useful infο.
    Thanκs for thе post. I'll definitely comeback.

    Have a look at my page :: weight loss system

    ReplyDelete
  26. AnonymousJuly 24, 2013

    Ι do belіeνе all the iԁeaѕ
    уou have introԁucеԁ for your poѕt.
    Тhey're very convincing and will certainly work. Still, the posts are too short for starters. May you please lengthen them a little from next time? Thanks for the post.

    my blog post; south beach diet

    ReplyDelete
  27. AnonymousJuly 27, 2013

    Heya i am fοr the first time heгe. Ι camе across this
    boаrd аnԁ I finԁ It really helpful & іt helped
    me out much. I hoрe to offer something back and help
    otherѕ like уou aided me.

    Αlso vіsit my webѕite - green tea

    ReplyDelete
  28. Тhis is а topic that's close to my heart... Take care! Exactly where are your contact details though?

    Also visit my blog ... [GET] PulseHover Download WP Plugin

    ReplyDelete
  29. AnonymousMay 13, 2019

    Thankfulness to my father who stated to me on the topic of this blog, this blog is in fact awesome.

    ReplyDelete
  30. AnonymousJune 16, 2019

    Howdy! I just want to offer you a hyge thumbs up
    for the excellent info you have got right here on thbis post.
    I am coming back to your wwbsite for more soon.

    ReplyDelete
  31. Its like you read my mind! You seem to know so much about
    this, such as you wrote the ebook in it or something.
    I believe that you simply could do with some percent to
    force the message house a little bit, but other than that, this is great blog.
    A fantastic read. I will certainly be back.

    ReplyDelete
  32. I am really enjoying the theme/design of your blog.
    Do you ever run into any browser compatibility problems?

    A few of my blog readers have complained about my blog not working correctly in Explorer but looks great in Safari.
    Do you have any advice to help fix this problem?

    ReplyDelete
  33. For newest information you have to go to
    see world wide web and on internet I found this web site
    as a finest site for latest updates.

    ReplyDelete
  34. Hello there, I found your blog by way of Google at the same time as searching for a comparable subject, your site got here up, it seems good.
    I've bookmarked it in my google bookmarks.

    ReplyDelete
  35. Whoah this blog is magnificent i like reading your articles.

    Keep up the good paintings! You understand, lots of persons
    are looking round for this info, you can help
    them greatly.

    ReplyDelete
  36. I enjoy looking through and I believe this website got some really utilitarian stuff on it!

    ReplyDelete
  37. Your way of telling everything in this piece of writing is
    genuinely pleasant, every one can effortlessly be aware of
    it, Thanks a lot.

    ReplyDelete
  38. Your mode of telling all in this paragraph is actually nice, every one be able to easily know it,
    Thanks a lot.

    ReplyDelete
  39. Hello my family member! I want to say that this article is awesome, great written and come with
    almost all important infos. I'd like to look
    extra posts like this.

    ReplyDelete

Your feedback may help others !!!

Facebook comments