Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
JainMaster authored Oct 20, 2020
1 parent 31e2104 commit 83572fe
Show file tree
Hide file tree
Showing 55 changed files with 4,871 additions and 0 deletions.
66 changes: 66 additions & 0 deletions 10.Strings/Check Palindrome.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Check Palindrome\n",
"Given a String s, check it its palindrome. Return true if string is palindrome, else return false.<br>\n",
"Palindrome strings are those, where string s and its reverse is exactly same.<br>\n",
"<br>\n",
"Input Format :<br>\n",
" String S<br>\n",
" <br>\n",
"Output Format :<br>\n",
"\"true\" if S is palindrome, else \"false\"<br>\n",
"<br>\n",
"Constraints :<br>\n",
"0 <= |S| <= 10^7<br>\n",
"where |S| represents the length of string, S.<br>\n",
"<br>\n",
"Sample Input 1 :<br>\n",
"abcdcba<br>\n",
"Sample Output 1 :<br>\n",
"true <br>\n",
"Sample Input 1 :<br>\n",
"abcd<br>\n",
"Sample Output 1 :<br>\n",
"false"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"str=input()\n",
"if str==str[::-1]:\n",
" print(\"true\")\n",
"else:\n",
" print(\"false\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
73 changes: 73 additions & 0 deletions 10.Strings/Check Permutation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Check Permutation\n",
"Given two strings, S and T, check if they are permutations of each other. Return true or false.<br>\n",
"Permutation means - length of both the strings should same and should contain same set of characters. Order of characters doesn't matter.<br>\n",
"Note : Input strings contain only lowercase english alphabets.<br>\n",
"<br>\n",
"<br>\n",
"Input format :<br>\n",
"Line 1 : String 1<br>\n",
"Line 2 : String 2<br>\n",
"<br>\n",
"Output format :<br>\n",
"'true' or 'false'<br>\n",
"<br>\n",
"Constraints :<br>\n",
"0 <= |S| <= 10^7<br>\n",
"0 <= |T| <= 10^7<br>\n",
"where |S| represents the length of string, S.<br>\n",
"<br>\n",
"Sample Input 1 :<br>\n",
"abcde<br>\n",
"baedc<br>\n",
"Sample Output 1 :<br>\n",
"true<br>\n",
"Sample Input 2 :<br>\n",
"abc<br>\n",
"cbd<br>\n",
"Sample Output 2 :<br>\n",
"false"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s=input()\n",
"d=input()\n",
"if sorted(d)==sorted(s):\n",
" print(\"true\")\n",
"else:\n",
" print(\"false\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
90 changes: 90 additions & 0 deletions 10.Strings/Compress the String.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Compress the String\n",
"Write a program to do basic string compression. For a character which is consecutively repeated more than once, replace consecutive duplicate occurrences with the count of repetitions.<br>\n",
"<br>\n",
"Exmple:<br>\n",
"If a String has 'x' repeated 5 times, replace this \"xxxxx\" with \"x5\".<br>\n",
"<br>\n",
"The string is compressed only when the repeated character count is more than 1.<br>\n",
"<br>\n",
"Note :<br>\n",
"Consecutive count of every character in the input string is less than equal to 9.<br>\n",
"<br>\n",
"<br>\n",
"Input Format :<br>\n",
"The first and the only line of input contains a string(no spaces in between).<br>\n",
"<br>\n",
"Output Format :<br>\n",
"The only line of output print the compressed string.<br>\n",
"<br>\n",
"Note:<br>\n",
"Return the compressed string and hence, no need to print.<br>\n",
"<br>\n",
"Constraints :<br>\n",
"0 <= |S| <= 10^7<br>\n",
"Where |S| represents the length of string, S.<br>\n",
"<br>\n",
"Time Limit: 1sec<br>\n",
"Sample Input 1 :<br>\n",
"aaabbccdsa<br>\n",
"Sample Output 1 :<br>\n",
"a3b2c2dsa<br>\n",
"Sample Input 2 :<br>\n",
"aaabbcddeeeee<br>\n",
"Sample Output 2 :<br>\n",
"a3b2cd2e5"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def ab(a):\n",
" i=0\n",
" x=''\n",
" while(i<len(a)):\n",
" j=i+1\n",
" c=1\n",
" while j<len(a) and (a[i]==a[j]):\n",
" j+=1\n",
" c+=1\n",
" if c==1:\n",
" x+=a[i]\n",
" else:\n",
" x+=a[i]+str(c)\n",
" i=j\n",
" return x\n",
"a=input()\n",
"print(ab(a))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
82 changes: 82 additions & 0 deletions 10.Strings/Highest Occurring Character.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Highest Occurring Character\n",
"Given a string, S, find and return the highest occurring character present in the given string.<br>\n",
"If there are 2 characters in the input string with same frequency, return the character which comes first.<br>\n",
"<br>\n",
"Note : Assume all the characters in the given string are lowercase.<br>\n",
"<br>\n",
"Input format :<br>\n",
"String S<br>\n",
"<br>\n",
"Output format :<br>\n",
"Highest occurring character<br>\n",
"<br>\n",
"Constraints :<br>\n",
"0 <= |S| <= 10^7<br>\n",
"where |S| represents the length of string, S.<br>\n",
"<br>\n",
"Sample Input 1:<br>\n",
"abdefgbabfba<br>\n",
"Sample Output 1:<br>\n",
"b<br>\n",
"Sample Input 2:<br>\n",
"xy<br>\n",
"Sample Output 2:<br>\n",
"x"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"myList=input()\n",
"newlist_d=[]\n",
"maxalpha=\"\"\n",
"maxno=0\n",
"\n",
"#Give list of all distinct words\n",
"for i in (myList):\n",
" if i not in newlist_d:\n",
" newlist_d.append(i)\n",
"#now let count\n",
"for ele in newlist_d:\n",
" count = 0\n",
" for l in range(len(myList)):\n",
" if ele==myList[l]:\n",
" count+=1\n",
" if count>maxno:\n",
" maxno=count\n",
" maxalpha=ele\n",
"print(maxalpha)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
65 changes: 65 additions & 0 deletions 10.Strings/Remove Consecutive Duplicates.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Remove Consecutive Duplicates\n",
"Given a string, S, remove all the consecutive duplicates that are present in the given string. That means, if 'aaa' is present in the string then it should become 'a' in the output string.<br>\n",
"<br>\n",
"Input format :<br>\n",
"String S<br>\n",
"<br>\n",
"Output format :<br>\n",
"Modified string<br>\n",
"<br>\n",
"Constraints :<br>\n",
"0 <= |S| <= 10^7<br>\n",
"where |S| represents the length of string, S.<br>\n",
"<br>\n",
"Sample Input 1:<br>\n",
"aabccbaa<br>\n",
"Sample Output 1:<br>\n",
"abcba<br>\n",
"Sample Input 2:<br>\n",
"xxyyzxx<br>\n",
"Sample Output 2:<br>\n",
"xyzx"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s=input()\n",
"s=s+\" \"\n",
"for i in range(len(s)-1):\n",
" if s[i]!=s[i+1]:\n",
" print(s[i],end=\"\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 83572fe

Please sign in to comment.