{"id":8854,"date":"2021-06-21T09:05:23","date_gmt":"2021-06-21T03:35:23","guid":{"rendered":"https:\/\/www.csestack.org\/?p=8854"},"modified":"2021-10-23T09:51:07","modified_gmt":"2021-10-23T04:21:07","slug":"second-smallest-number-array","status":"publish","type":"post","link":"https:\/\/www.csestack.org\/second-smallest-number-array\/","title":{"rendered":"Second Largest\/Smallest Number in Array in C\/C++, Java and Python"},"content":{"rendered":"\n<p>In an earlier tutorial, we have seen how to find the <a href=\"https:\/\/www.csestack.org\/smallest-largest-number-array\/\">smallest or largest number from the integer array<\/a>. In this tutorial, we are going to find the second smallest number in an array <strong>in a single iteration<\/strong>.<\/p>\n\n\n\n<p><strong>Input:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>integer array<\/li><\/ul>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Print second smallest integer in given array.<\/li><\/ul>\n\n\n\n<p>We can easily find the second smallest number by traversing the array twice. In the first traversing, find the first smallest number. And in second traversing find the second smallest number. But this is not the optimal solution to the problem.<\/p>\n\n\n\n<p>Finding second smallest number in array with single iteration is a bit tricky. Here is the algorithm to solve this problem.<\/p>\n\n\n\n<p>This question was asked in the <a href=\"https:\/\/www.csestack.org\/goldman-sachs-online-coding-test-questions\/\">Goldman Sachs coderpad online interview<\/a>.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69fd6a9e47ec7\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #000000;color:#000000\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #000000;color:#000000\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69fd6a9e47ec7\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.csestack.org\/second-smallest-number-array\/#Algorithm\" >Algorithm<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.csestack.org\/second-smallest-number-array\/#CC_Program\" >C\/C++ Program<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.csestack.org\/second-smallest-number-array\/#Java_Program\" >Java Program<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.csestack.org\/second-smallest-number-array\/#Python_Program\" >Python Program<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.csestack.org\/second-smallest-number-array\/#Complexity\" >Complexity<\/a><\/li><\/ul><\/nav><\/div>\n<h4 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"Algorithm\"><\/span>Algorithm<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>Compare the first two elements from the array.<ul><li>Initialize the <code>small_first<\/code> with the smallest number.<\/li><li>Initialize the <code>small_second<\/code> with the smallest number.<\/li><\/ul><\/li><li>Loop over internet array from 3rd number.<ul><li>If the current number is smaller than small_first<ul><li>assign small_first to small_second<\/li><li>assign a current number to small_first <\/li><\/ul><\/li><\/ul><\/li><li>Print small_second.<\/li><\/ul>\n\n\n\n<p>If you understand the logic from the above algorithm, you can solve the problem in any programming language. Let&#8217;s implement this algorithm in different programming languages.<\/p>\n\n\n\n<p><strong>Note:<\/strong> By changing some conditional statements, you can also implement the program to find the <strong>second largest number in the given array<\/strong>. That is just another story. Let&#8217;s stick with the original problem first.<\/p>\n\n\n\n<h4 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"CC_Program\"><\/span>C\/C++ Program<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p><strong>Prerequisites:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.csestack.org\/traversing-array-print-c-program\/\">Array in C\/C++<\/a><\/li><li><a href=\"https:\/\/www.csestack.org\/difference-do-while-for-loop-c-code-example-syntax\/\">for loop in C\/C++<\/a><\/li><li><a href=\"https:\/\/www.csestack.org\/if-else-nested-programming-example-c-java-python\/\">if-else statement in C\/C++<\/a><\/li><\/ul>\n\n\n\n<p><strong>C\/C++ Code:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &lt;stdio.h&gt;\n   \nint main() {\n    \/\/initialize array\n    int arr[7] = {34, 62, 56, 13, 7, 9, 17};\n    int i=0;\n \n    int small_first = arr[0];\n    int small_second = arr[0];\n  \n    \/\/initializ first and second smallest number\n    if(arr[0] &gt; arr[1]) {\n        small_first = arr[1];\n        small_second = arr[0];\n    }\n    else {\n        small_first = arr[0];\n        small_second = arr[1];\n    }\n \n    for(i = 2; i &lt; 7; i++) {\n  \n         \/\/compare smallest number with current number\n        if(arr[i]&lt;=small_first) {\n            small_second = small_first;\n            small_first = arr[i];\n        }\n        else if(arr[i]&lt;small_second){\n            small_second = arr[i];\n        }\n    }\n   \n    \/\/print second smallest number from array\n    printf(&quot;Second smallest number in array is %d.&quot;, small_second);\n  \n    return 0;\n}<\/pre><\/div>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Second smallest number in array is 9.<\/pre>\n\n\n\n<h4 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"Java_Program\"><\/span>Java Program<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Prerequisites:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.csestack.org\/control-flow-statements-java\/\">flow-control statement in Java<\/a><\/li><\/ul>\n\n\n\n<p><strong>Java Code:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-java&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">public class Smallest_Largest_Element_Array {  \n    public static void main(String[] args) {  \n    \n        \/\/ initialize the array  \n        int [] arr = new int [] {67, 83, 8, 71, 29, 3, 48};  \n         \n        int small_first = arr[0];\n        int small_second = arr[0];\n  \n        \/\/initializ first and second smallest number\n        if(arr[0] &gt; arr[1]) {\n            small_first = arr[1];\n            small_second = arr[0];\n        }\n        else {\n            small_first = arr[0];\n            small_second = arr[1];\n        }\n  \n        \/\/traverse all elements in the array  \n        for (int i = 2; i &lt; arr.length; i++) {  \n  \n             \/\/compare smallest number with current number\n            if(arr[i]&lt;=small_first) {\n                small_second = small_first;\n                small_first = arr[i];\n            }\n            else if(arr[i]&lt;small_second){\n                small_second = arr[i];\n            }\n        }\n  \n        \/\/print smallest number from the array\n        System.out.println(&quot;Second smallest element in the array: &quot; + small_second);\n \n    }  \n} <\/pre><\/div>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Second smallest element in the array: 8<\/pre>\n\n\n\n<h4 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"Python_Program\"><\/span>Python Program<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p><strong>Prerequisites:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.csestack.org\/python-list\/\">Python List<\/a>&nbsp;(Python has a list that works similarly to the array from C\/C++ and Java.)<\/li><li><a href=\"https:\/\/www.csestack.org\/python-for-while-loop-else\/\">for-loop in Python<\/a><\/li><li><a href=\"https:\/\/www.csestack.org\/elif-nested-if-else-in-python-3-code-example-syntax\/\">if-else in Python<\/a><\/li><\/ul>\n\n\n\n<p><strong>Python Code:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:false,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">#initialize the Python list\nint_arr = [45, 56, 83, 4, 11, 28, 36]\n  \nsmall_first = int_arr[0]\nsmall_second = int_arr[0]\n  \n#initializ first and second smallest number\nif int_arr[0] &gt; int_arr[1]:\n    small_first = int_arr[1]\n    small_second = int_arr[0]\nelse:\n    small_first = int_arr[0]\n    small_second = int_arr[1]\n  \n#loop over all the number in the list\nfor num in int_arr[2:]:\n\n    #compare smallest number with current number\n    if num&lt;=small_first:\n        small_second = small_first\n        small_first = num\n    elif num&lt;small_second:\n        small_second = num\n\nprint(f&quot;Second smallest number in the Python list: {small_second}&quot;)<\/pre><\/div>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Second smallest number in the Python list: 11<\/pre>\n\n\n\n<h4 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"Complexity\"><\/span>Complexity<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>To find the second smallest number from the array, we are traversing the array only once. Each element in the array is visited once. So the time complexity of this algorithm is <code>O(n)<\/code>. Here, <code>n<\/code> is the size of the array.<\/p>\n\n\n\n<p>We are using extra space to store the first and second smallest number but it is constant (irrespective of the size of the array.) <\/p>\n\n\n\n<p><strong>What&#8217;s Next?<\/strong><\/p>\n\n\n\n<p>Write a program to find the <strong>second largest number in the array<\/strong> and share it with me in the comment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Write a program to find the second smallest number in array in C\/C++, Java and Python. Second largest element in list.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,7,39,73],"tags":[2,5,67,72],"class_list":["post-8854","post","type-post","status-publish","format-standard","hentry","category-c-cpp","category-code","category-java","category-python","tag-code","tag-cpp","tag-java","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Second Largest\/Smallest Number in Array in C\/C++, Java and Python<\/title>\n<meta name=\"description\" content=\"Write a program to find the second smallest number in array in C\/C++, Java and Python. Second largest element in list.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.csestack.org\/second-smallest-number-array\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Second Largest\/Smallest Number in Array in C\/C++, Java and Python\" \/>\n<meta property=\"og:description\" content=\"Write a program to find the second smallest number in array in C\/C++, Java and Python. Second largest element in list.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.csestack.org\/second-smallest-number-array\/\" \/>\n<meta property=\"og:site_name\" content=\"CSEstack\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/aniruddha.ca\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/aniruddha.ca\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-21T03:35:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-23T04:21:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.csestack.org\/wp-content\/uploads\/2024\/01\/csestack-blog.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Aniruddha Chaudhari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ani_chaudhari\" \/>\n<meta name=\"twitter:site\" content=\"@ani_chaudhari\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aniruddha Chaudhari\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/second-smallest-number-array\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/second-smallest-number-array\\\/\"},\"author\":{\"name\":\"Aniruddha Chaudhari\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\"},\"headline\":\"Second Largest\\\/Smallest Number in Array in C\\\/C++, Java and Python\",\"datePublished\":\"2021-06-21T03:35:23+00:00\",\"dateModified\":\"2021-10-23T04:21:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/second-smallest-number-array\\\/\"},\"wordCount\":398,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\"},\"keywords\":[\"Code\",\"cpp\",\"Java\",\"Python\"],\"articleSection\":[\"C \\\/ C++\",\"Code\",\"JAVA\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.csestack.org\\\/second-smallest-number-array\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/second-smallest-number-array\\\/\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/second-smallest-number-array\\\/\",\"name\":\"Second Largest\\\/Smallest Number in Array in C\\\/C++, Java and Python\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#website\"},\"datePublished\":\"2021-06-21T03:35:23+00:00\",\"dateModified\":\"2021-10-23T04:21:07+00:00\",\"description\":\"Write a program to find the second smallest number in array in C\\\/C++, Java and Python. Second largest element in list.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/second-smallest-number-array\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.csestack.org\\\/second-smallest-number-array\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/second-smallest-number-array\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.csestack.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Second Largest\\\/Smallest Number in Array in C\\\/C++, Java and Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#website\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/\",\"name\":\"CSEstack\",\"description\":\"Computer Science &amp; Programming Portal\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.csestack.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.csestack.org\\\/#\\\/schema\\\/person\\\/634ef1a9c4f38b0d340c6d45fa771218\",\"name\":\"Aniruddha Chaudhari\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\",\"url\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\",\"contentUrl\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\",\"width\":634,\"height\":634,\"caption\":\"Aniruddha Chaudhari\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.csestack.org\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/Aniruddha-Chaudhari.jpg\"},\"description\":\"I am a Python enthusiast who loves Linux and Vim. I hold a Master of Computer Science degree from NIT Trichy and have 10 years of experience in the IT industry, focusing on the Software Development Lifecycle from Requirements Gathering, Design, Development to Deployment. I have worked at IBM, Ericsson, and NetApp, and I share my knowledge on CSEstack.org.\",\"sameAs\":[\"https:\\\/\\\/www.csestack.org\",\"https:\\\/\\\/www.facebook.com\\\/aniruddha.ca\",\"pythonwithani\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/aniruddha28\\\/\",\"https:\\\/\\\/x.com\\\/ani_chaudhari\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCw0a__B0eJsvCujkSIfLTAA\"],\"url\":\"https:\\\/\\\/www.csestack.org\\\/author\\\/anicse\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Second Largest\/Smallest Number in Array in C\/C++, Java and Python","description":"Write a program to find the second smallest number in array in C\/C++, Java and Python. Second largest element in list.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.csestack.org\/second-smallest-number-array\/","og_locale":"en_US","og_type":"article","og_title":"Second Largest\/Smallest Number in Array in C\/C++, Java and Python","og_description":"Write a program to find the second smallest number in array in C\/C++, Java and Python. Second largest element in list.","og_url":"https:\/\/www.csestack.org\/second-smallest-number-array\/","og_site_name":"CSEstack","article_publisher":"https:\/\/www.facebook.com\/aniruddha.ca","article_author":"https:\/\/www.facebook.com\/aniruddha.ca","article_published_time":"2021-06-21T03:35:23+00:00","article_modified_time":"2021-10-23T04:21:07+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.csestack.org\/wp-content\/uploads\/2024\/01\/csestack-blog.jpg","type":"image\/jpeg"}],"author":"Aniruddha Chaudhari","twitter_card":"summary_large_image","twitter_creator":"@ani_chaudhari","twitter_site":"@ani_chaudhari","twitter_misc":{"Written by":"Aniruddha Chaudhari","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.csestack.org\/second-smallest-number-array\/#article","isPartOf":{"@id":"https:\/\/www.csestack.org\/second-smallest-number-array\/"},"author":{"name":"Aniruddha Chaudhari","@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218"},"headline":"Second Largest\/Smallest Number in Array in C\/C++, Java and Python","datePublished":"2021-06-21T03:35:23+00:00","dateModified":"2021-10-23T04:21:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.csestack.org\/second-smallest-number-array\/"},"wordCount":398,"commentCount":0,"publisher":{"@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218"},"keywords":["Code","cpp","Java","Python"],"articleSection":["C \/ C++","Code","JAVA","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.csestack.org\/second-smallest-number-array\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.csestack.org\/second-smallest-number-array\/","url":"https:\/\/www.csestack.org\/second-smallest-number-array\/","name":"Second Largest\/Smallest Number in Array in C\/C++, Java and Python","isPartOf":{"@id":"https:\/\/www.csestack.org\/#website"},"datePublished":"2021-06-21T03:35:23+00:00","dateModified":"2021-10-23T04:21:07+00:00","description":"Write a program to find the second smallest number in array in C\/C++, Java and Python. Second largest element in list.","breadcrumb":{"@id":"https:\/\/www.csestack.org\/second-smallest-number-array\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.csestack.org\/second-smallest-number-array\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.csestack.org\/second-smallest-number-array\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.csestack.org\/"},{"@type":"ListItem","position":2,"name":"Second Largest\/Smallest Number in Array in C\/C++, Java and Python"}]},{"@type":"WebSite","@id":"https:\/\/www.csestack.org\/#website","url":"https:\/\/www.csestack.org\/","name":"CSEstack","description":"Computer Science &amp; Programming Portal","publisher":{"@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.csestack.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.csestack.org\/#\/schema\/person\/634ef1a9c4f38b0d340c6d45fa771218","name":"Aniruddha Chaudhari","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg","url":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg","contentUrl":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg","width":634,"height":634,"caption":"Aniruddha Chaudhari"},"logo":{"@id":"https:\/\/www.csestack.org\/wp-content\/uploads\/2019\/03\/Aniruddha-Chaudhari.jpg"},"description":"I am a Python enthusiast who loves Linux and Vim. I hold a Master of Computer Science degree from NIT Trichy and have 10 years of experience in the IT industry, focusing on the Software Development Lifecycle from Requirements Gathering, Design, Development to Deployment. I have worked at IBM, Ericsson, and NetApp, and I share my knowledge on CSEstack.org.","sameAs":["https:\/\/www.csestack.org","https:\/\/www.facebook.com\/aniruddha.ca","pythonwithani","https:\/\/www.linkedin.com\/in\/aniruddha28\/","https:\/\/x.com\/ani_chaudhari","https:\/\/www.youtube.com\/channel\/UCw0a__B0eJsvCujkSIfLTAA"],"url":"https:\/\/www.csestack.org\/author\/anicse\/"}]}},"_links":{"self":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts\/8854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/comments?post=8854"}],"version-history":[{"count":8,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts\/8854\/revisions"}],"predecessor-version":[{"id":9275,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/posts\/8854\/revisions\/9275"}],"wp:attachment":[{"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/media?parent=8854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/categories?post=8854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.csestack.org\/wp-json\/wp\/v2\/tags?post=8854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}