{"id":319,"date":"2023-01-12T12:54:02","date_gmt":"2023-01-12T12:54:02","guid":{"rendered":"https:\/\/premsvmm.com\/?p=319"},"modified":"2023-01-12T14:00:23","modified_gmt":"2023-01-12T14:00:23","slug":"re-arrange-string-in-sequence-order","status":"publish","type":"post","link":"https:\/\/premsvmm.com\/index.php\/2023\/01\/12\/re-arrange-string-in-sequence-order\/","title":{"rendered":"Re-Arrange String in sequence order"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">Give an string <strong>'abcd'<\/strong> and an another string <strong>'efghij'<\/strong>, print the sequence in alternate order, if any of the string is ended, append the rest of the string to the other string<div class=\"open_grepper_editor\" title=\"Edit &amp; Save To Grepper\"><\/pre>\n\n\n\n<div class=\"inherit-container-width wp-block-group has-ast-global-color-4-background-color has-background is-layout-constrained wp-block-group-is-layout-constrained\">\n<p><strong>Input : <\/strong>&nbsp;abcd , efghij<\/p>\n\n\n\n<p><strong>Output:<\/strong>  aebfcgdhij<\/p>\n<\/div>\n\n\n\n<p><strong>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;eclipse&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Java&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;java&quot;}\">public static String reArrangeString(String input1, String input2) {\n    int length1 = 0, length2 = 0;\n    StringBuilder stringBuilder = new StringBuilder();\n    while (length1 &lt; input1.length() &amp;&amp; length2 &lt; input2.length()) {\n        stringBuilder.append(input1.charAt(length1));\n        stringBuilder.append(input2.charAt(length2));\n        length1++;\n        length2++;\n    }\n\n    if (length1 != 0) {\n        stringBuilder.append(input1.substring(length1));\n    }\n    if (length2 != 0) {\n        stringBuilder.append(input2.substring(length2));\n    }\n    return stringBuilder.toString();\n\n}\n\npublic static void main(String[] args) {\n    System.out.println(reArrangeString(&quot;abcd&quot;, &quot;efghij&quot;)); \/\/ aebfcgdhij\n    System.out.println(reArrangeString(&quot;a&quot;, &quot;a&quot;)); \/\/ aa\n    System.out.println(reArrangeString(&quot;ab&quot;, &quot;a&quot;)); \/\/ aab\n    System.out.println(reArrangeString(&quot;a&quot;, &quot;ab&quot;)); \/\/ aab\n    System.out.println(reArrangeString(&quot;ab&quot;, &quot;ab&quot;)); \/\/ abab\n    System.out.println(reArrangeString(&quot;abc&quot;, &quot;abc&quot;)); \/\/ aabbcc\n    System.out.println(reArrangeString(&quot;&quot;, &quot;abc&quot;)); \/\/ abc\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Give an string &#8216;abcd&#8217; and an another string &#8216;efghij&#8217;, print the sequence in alternate order, if any of the string is ended, append the rest of the string to the other string Input : &nbsp;abcd , efghij Output: aebfcgdhij Code:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[10],"tags":[11],"_links":{"self":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/319"}],"collection":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/comments?post=319"}],"version-history":[{"count":10,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/319\/revisions"}],"predecessor-version":[{"id":337,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/319\/revisions\/337"}],"wp:attachment":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/media?parent=319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/categories?post=319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/tags?post=319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}