Skip to main content

Strings Manipulation Algorithms











find the longest substring with at most k repeating characters,
to make it more clear, at most k repeating characters means in the substring, the max count(frequency) of one or more chars is k
-->








1)/*word break problem*/



2)/*Permute  String*/




3)/*Grouping Anagrams */



4)/*sort by last name : comaparator in java 8 */


P.S the following has been picked up from internet & is not original work 


5)/* Find if a word  is present in a sentence */



 public static boolean searchString(String find){  
          return ("Yellow Banana,Green Apple red Apple ,Oranges ".indexOf(find)== -1)?false:true;  
      }  


6)/*  Check Panagram */




 Working on optimal solution for

7)/* Check Anagrams */


Preview:
 public static void checkDigits(){
  String first = "Morning10";
  //Pattern pattern = Pattern.compile(".*\\D.*");
  Pattern pattern = Pattern.compile(".*[^0-9].*");
  Matcher matcher = pattern.matcher(first);
  if(matcher.matches()) System.out.println("yes there are digits present !");
 }

8)/* Find first non repeating character*/

Solution 1

Preview:
 public static void nonRepeatingChar(){  
           String first = "Morning";  
           for(int i=0;i
           String tempStr = 
           first.substring(0, i)+first.substring(i+1,first.length());  
                     if(tempStr.indexOf(first.charAt(i)) == -1 )  
                          System.out.println("The non repeating character is :"+first.charAt(i));  
                }  
           }  


Solution 2
-


-


9)/* Given two strings s1, s2, write a function that returns true if s2 is a special substring s1. 

A special substring s2 is such that the s1 contains s2 where each character in s2 appears in sequence in s1, but there can be any characters in s1 in between the sequence.

 Example: 
 isSpecialSubstring('abcdefg', 'abc') => true 
 isSpecialSubstring('abcdefg', 'acg') => true 
 isSpecialSubstring('abcdefg', 'acb') => false; 

 The first two are abc and acg appears in 'abcdefg' in that order, although there might be multiple chars between the next character in s2. The last one is false, because in 'acb' the character 'b' appears before the character 'c' in 'abcdefg' Hope thats clear. * */



 public class SpecialString {  

      public static void main(String[] args) {  
           System.out.println("Here is my the answer case 1:"+isSpecialSubstring("abcdefg", "abc"));  
           System.out.println("Here is my the answer case 2:"+isSpecialSubstring("abcdefg", "acg"));   
           System.out.println("Here is my the answer case 3:"+isSpecialSubstring("abcdefg", "acb"));   
      }  
      public static boolean isSpecialSubstring(String original, String theSubString){            
           if(original.indexOf(theSubString, 0) !=-1){      return true;  
           }else{  
                String order = "";  
                for(int i =0;i<original.length();i++){  
                     String c = String.valueOf(original.charAt(i));  
                     if(theSubString.contains(c)) order = order.concat(c);  
                }  
                if(order.indexOf(theSubString, 0) !=-1)return true;  
           }            
           return false; }  
 }  


10)/*Max ocurring character in String */

      public static void maxOccuringCharacter() {  
           String str = "Red roses blue sky green plants brown earth let's conserve";  
           TreeMap map = new TreeMap();  
           for(int i =0;i         NavigableMap nmap=map.descendingMap();  
           //NavigableMap nmap=map.subMap(fromKey, toKey)  
           //NavigableMap nmap=map.headMap(toKey, inclusive)  
        //NavigableMap nmap=map.tailMap(fromKey, inclusive)  
             for(Character ch : map.keySet()){  
                   int c = map.get(ch);  
                      System.out.println("Character is :"+ ch +" Count is :"+c);   
                     // break;  
             }  
      }  





11) 

12)
13)
14)

https://codingsec.net/2016/07/skills-companies-like-google-expect-software-engineers/







Comments

Popular posts from this blog

Microservices Design patterns

What are microservices? Microservices - also known as the microservice architecture - is an architectural style that structures an application as a collection of services that are Highly maintainable and testable Loosely coupled Independently deployable Organized around business capabilities Owned by a small team The microservice architecture enables the rapid, frequent and reliable delivery of large, complex applications. It also enables an organization to evolve its technology stack. You are developing a server-side enterprise application. It must support a variety of different clients including desktop browsers, mobile browsers and native mobile applications. The application might also expose an API for 3rd parties to consume. It might also integrate with other applications via either web services or a message broker. The application handles requests (HTTP requests and messages) by executing business logic; accessing a database; exchanging messages with other systems; and returni...

GraphQL

What is GraphQL  API Standard invented & open-sourced by Facebook Alternative to  REST API  enables declarative data fetching  exposes single endpoint & responds to queries How it works?  Why Graphql? Improvises performance by reducing the data that is to be transferred over the internet Variety of different frontend frameworks and platforms on client-side Fast development speed & expectation for rapid feature development Why Graphql is better than REST? Flexibility & efficient  No more over /under fetching of data Over fetching : Under fetching: Insightful analytics  Schema serves as contract between client and server CORE CONCEPTS : SDL :SCHEMA DEFINITION LANGUAGE Writing Data with mutations 3 kinds of mutations creating new data updating existing data deleting existing data

Jackson

<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId> jackson-core </artifactId> <version>2.9.6</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId> jackson-annotations </artifactId> <version>2.9.6</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId> jackson-databind </artifactId> <version>2.9.6</version> </dependency> CBOR encoded data with Jackson <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-cbor</artifactId> <version>2.9.6</version> </dependency> In order to read and write MessagePack encoded data <dependency> <groupId>org.msgpack</groupId> <artifactId>jackson-dataformat-msgp...