top of page
Search
Writer's pictureAbhinaw Tripathi

How will you check,given two strings are permutation of the other.


Example: "god" permutation will be "dog"

Solution:

public String sort(String s)

{

char[] content = s.toCharArray();

java.util.Arrays.sort(content);

return new String(content);

}

public boolean permutation(String s ,String t)

{

if(s.lenght() ! = t.length())

{

return false;

}

return sort(s).equals(sort(t));

}

Though this solution is not as optimal in some cases.

2 views0 comments

Recent Posts

See All
bottom of page