{"id":445,"date":"2023-02-01T16:51:32","date_gmt":"2023-02-01T16:51:32","guid":{"rendered":"https:\/\/premsvmm.com\/?p=445"},"modified":"2023-02-01T16:51:32","modified_gmt":"2023-02-01T16:51:32","slug":"valid-string","status":"publish","type":"post","link":"https:\/\/premsvmm.com\/index.php\/2023\/02\/01\/valid-string\/","title":{"rendered":"Valid String"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\"> A string to be valid if all characters of the string appear the same number of times<\/pre>\n\n\n\n<p>Input : aabbcc<\/p>\n\n\n\n<p>Output: valid<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Code<\/h4>\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;idea&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;}\">package wordpress;\n\nimport java.util.LinkedHashMap;\nimport java.util.Locale;\n\npublic class ValidString {\n\n    public static String validateTheInputString(String input) {\n        input = input.toLowerCase(Locale.ROOT);\n        LinkedHashMap&lt;Character, Integer&gt; hashMap = new LinkedHashMap&lt;&gt;();\n        for (Character c : input.toCharArray()) {\n            if (hashMap.containsKey(c)) {\n                int count = hashMap.get(c);\n                hashMap.put(c, ++count);\n            } else {\n                hashMap.put(c, 1);\n            }\n        }\n        Integer initialValue = hashMap.get(input.toCharArray()[0]);\n        for (Integer value : hashMap.values()) {\n            if (value != initialValue) {\n                return &quot;Invalid&quot;;\n            }\n        }\n        return &quot;valid&quot;;\n    }\n\n    public static void main(String[] args) {\n        System.out.println(validateTheInputString(&quot;aabbcc&quot;)); \/\/ valid\n        System.out.println(validateTheInputString(&quot;abcd&quot;)); \/\/ valid\n        System.out.println(validateTheInputString(&quot;a&quot;)); \/\/ valid\n        System.out.println(validateTheInputString(&quot;aab&quot;)); \/\/ invalid\n        System.out.println(validateTheInputString(&quot;aA&quot;)); \/\/ valid\n    }\n}\n<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>A string to be valid if all characters of the string appear the same number of times Input : aabbcc Output: valid 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\/445"}],"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=445"}],"version-history":[{"count":2,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/445\/revisions"}],"predecessor-version":[{"id":447,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/posts\/445\/revisions\/447"}],"wp:attachment":[{"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/media?parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/categories?post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/premsvmm.com\/index.php\/wp-json\/wp\/v2\/tags?post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}