Skip to content
- Tutorials
- Python Tutorial
- Taking Input in Python
- Python Operators
- Python Data Types
- Python Loops and Control Flow
- Python Functions
- Python OOPS Concept
- Python Data Structures
- Python Exception Handling
- Python File Handling
- Python Exercises
- Java
- Java Programming Language
- Java Collections
- Java 8 Tutorial
- Java Programs
- Java Interview Questions
- Java Exercises
- Java Quiz
- Java Projects
- Advance Java
- Programming Languages
- System Design
- Interview Corner
- Computer Science Subjects
- DevOps
- Linux
- Software Testing
- Databases
- Android
- Excel
- Mathematics
- Python Tutorial
- DSA
- Data Structures
- Algorithms
- Analysis of Algorithms
- Searching Algorithms
- Sorting Algorithms
- Greedy Algorithms
- Dynamic Programming
- Graph Algorithms
- Pattern Searching
- Recursion
- Backtracking
- Divide and Conquer
- Mathematical Algorithms
- Geometric Algorithms
- Bitwise Algorithms
- Randomized Algorithms
- Branch and Bound
- Algorithms Tutorial
- DSA Tutorial
- Practice
- All DSA Problems
- Problem of the Day
- Company Wise Coding Practice
- GfG SDE Sheet
- Practice Problems Difficulty Wise
- Language Wise Coding Practice
- Curated DSA Lists
- Competitive Programming
- Company Wise SDE Sheets
- DSA Cheat Sheets
- Top Interview Questions
- Puzzles
- Data Science
- Web Tech
- Courses
-
Last Updated : 31 May, 2021
Summarize
Comments
Improve
Given a decoded string str which was decoded with the following encoding algorithm:
Write down the middle character of the string then delete it and repeat the process until there are no characters left. For example, “abba” will be encoded as “bbaa”.
Note that the middle character is the first character of the two middle characters when the length of the string is even.
Examples:Input: "ofrsgkeeeekgs"Output: geeksforgeeksInput: str = "bbaa"Output: abba
Approach: It can be observed that while decoding the string, the first letter of the encoded string becomes the median of the decoded string. So first, write the very first character of the encoded string and remove it from the encoded string then start adding the first character of the encoded string first to the left and then to the right of the decoded string and do this task repeatedly till the encoded string becomes empty.
For example:Encoded String Decoded Stringofrsgkeeeekgs ofrsgkeeeekgs forsgkeeeekgs forsgkeeeekgs sforgkeeeekgs sforgkeeeekgs ksforgeeeekgs ksforgeeeekgs eksforgeeekgs eksforgeeekgs eeksforgeekgs eeksforgeekgs geeksgorgeeks geeksforgeeks
Below is the implementation of the above approach:
C++
// C++ implementation of the approach
#include <bits/stdc++.h>
using
namespace
std;
// Function to decode and print
// the original string
void
decodeStr(string str,
int
len)
{
// To store the decoded string
char
c[len] =
""
;
int
med, pos = 1, k;
// Getting the mid element
if
(len % 2 == 1)
med = len / 2;
else
med = len / 2 - 1;
// Storing the first element of the
// string at the median position
c[med] = str[0];
// If the length is even then store
// the second element also
if
(len % 2 == 0)
c[med + 1] = str[1];
// k represents the number of characters
// that are already stored in the c[]
if
(len & 1)
k = 1;
else
k = 2;
for
(
int
i = k; i < len; i += 2) {
c[med - pos] = str[i];
// If string length is odd
if
(len % 2 == 1)
c[med + pos] = str[i + 1];
// If it is even
else
c[med + pos + 1] = str[i + 1];
pos++;
}
// Print the decoded string
for
(
int
i = 0; i < len; i++)
cout << c[i];
}
// Driver code
int
main()
{
string str =
"ofrsgkeeeekgs"
;
int
len = str.length();
decodeStr(str, len);
return
0;
}
Java
// Java implementation of the approach
class
GFG{
// Function to decode and print
// the original String
static
void
decodeStr(String str,
int
len)
{
// To store the decoded String
char
[]c =
new
char
[len];
int
med, pos =
1
, k;
// Getting the mid element
if
(len %
2
==
1
)
med = len /
2
;
else
See AlsoPython encode() and decode() Functions - AskPythonMy Guide to Encoding/Decoding Text Data with PythonStata | Australia Indonesia New ZealandTextEncoder: encode() method - Web APIs | MDNmed = len /
2
-
1
;
// Storing the first element of the
// String at the median position
c[med] = str.charAt(
0
);
// If the length is even then store
// the second element also
if
(len %
2
==
0
)
c[med +
1
] = str.charAt(
1
);
// k represents the number of characters
// that are already stored in the c[]
if
(len %
2
==
1
)
k =
1
;
else
k =
2
;
for
(
int
i = k; i < len; i +=
2
)
{
c[med - pos] = str.charAt(i);
// If String length is odd
if
(len %
2
==
1
)
c[med + pos] = str.charAt(i +
1
);
// If it is even
else
c[med + pos +
1
] = str.charAt(i +
1
);
pos++;
}
// Print the decoded String
for
(
int
i =
0
; i < len; i++)
System.out.print(c[i]);
}
// Driver code
public
static
void
main(String[] args)
{
String str =
"ofrsgkeeeekgs"
;
int
len = str.length();
decodeStr(str, len);
}
}
// This code is contributed by 29AjayKumar
Python3
# Python3 implementation of the
# above approach
# Function to decode and print
# the original string
def
decodeStr(
str
,
len
):
# To store the decoded string
c
=
[""
for
i
in
range
(
len
)]
pos
=
1
# Getting the mid element
if
(
len
%
2
=
=
1
):
med
=
int
(
len
/
2
)
else
:
med
=
int
(
len
/
2
-
1
)
# Storing the first element
# of the string at the
# median position
c[med]
=
str
[
0
]
# If the length is even
# then store the second
# element also
if
(
len
%
2
=
=
0
):
c[med
+
1
]
=
str
[
1
]
# k represents the number
# of characters that are
# already stored in the c[]
if
(
len
&
1
):
k
=
1
else
:
k
=
2
for
i
in
range
(k,
len
,
2
):
c[med
-
pos]
=
str
[i]
# If string length is odd
if
(
len
%
2
=
=
1
):
c[med
+
pos]
=
str
[i
+
1
]
# If it is even
else
:
c[med
+
pos
+
1
]
=
str
[i
+
1
]
pos
+
=
1
# Print the decoded string
print
(
*
c, sep
=
"")
# Driver code
str
=
"ofrsgkeeeekgs"
len
=
len
(
str
)
decodeStr(
str
,
len
)
# This code is contributed by avanitrachhadiya2155
C#
// C# implementation of the approach
using
System;
class
GFG{
// Function to decode and print
// the original String
static
void
decodeStr(String str,
int
len)
{
// To store the decoded String
char
[]c =
new
char
[len];
int
med, pos = 1, k;
// Getting the mid element
if
(len % 2 == 1)
med = len / 2;
else
med = len / 2 - 1;
// Storing the first element of the
// String at the median position
c[med] = str[0];
// If the length is even then store
// the second element also
if
(len % 2 == 0)
c[med + 1] = str[1];
// k represents the number of characters
// that are already stored in the c[]
if
(len % 2 == 1)
k = 1;
else
k = 2;
for
(
int
i = k; i < len; i += 2)
{
c[med - pos] = str[i];
// If String length is odd
if
(len % 2 == 1)
c[med + pos] = str[i + 1];
See AlsoENCODE function// If it is even
else
c[med + pos + 1] = str[i + 1];
pos++;
}
// Print the decoded String
for
(
int
i = 0; i < len; i++)
Console.Write(c[i]);
}
// Driver code
public
static
void
Main(String[] args)
{
String str =
"ofrsgkeeeekgs"
;
int
len = str.Length;
decodeStr(str, len);
}
}
// This code is contributed by sapnasingh4991
Javascript
<script>
// JavaScript implementation of the approach
// Function to decode and print
// the original string
function
decodeStr(str, len)
{
// To store the decoded string
var
c = Array(len).fill(
""
);
var
med, pos = 1, k;
// Getting the mid element
if
(len % 2 == 1)
med = parseInt(len / 2);
else
med = parseInt(len / 2) - 1;
// Storing the first element of the
// string at the median position
c[med] = str[0];
// If the length is even then store
// the second element also
if
(len % 2 == 0)
c[med + 1] = str[1];
// k represents the number of characters
// that are already stored in the c[]
if
(len & 1)
k = 1;
else
k = 2;
for
(
var
i = k; i < len; i += 2) {
c[med - pos] = str[i];
// If string length is odd
if
(len % 2 == 1)
c[med + pos] = str[i + 1];
// If it is even
else
c[med + pos + 1] = str[i + 1];
pos++;
}
// Print the decoded string
for
(
var
i = 0; i < len; i++)
{
document.write(c[i]);
}
}
// Driver code
var
str =
"ofrsgkeeeekgs"
;
var
len = str.length;
decodeStr(str, len);
</script>
Output:
geeksforgeeks
The Complexity: O(n)
Please Login to comment...
Similar Reads
Decode an Encoded Base 64 String to ASCII String
Prerequisite : What is base64 Encoding and why we encode strings to base64 formatBase64 encoding is performed at sending node before transmitting bits over a network, and receiving node decodes that encoded data back to original ASCII string. Base64 character set is // 64 characterschar_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012
15+ min read
Decode a string recursively encoded as count followed by substring | Set 2 (using Recursion)
An encoded string str is given. The pattern in which the string is encoded is as follows. <count>[sub_str] ==> The substring 'sub_str' appears count times. The task is to decode this string str. Examples: Input: str = "1[b]"Output: bExplanation: The substring 'b' is repeated 1 time. Input: str = "2[ab]"Output: ababExplanation: The substrin
9 min read
Decode a string recursively encoded as count followed by substring
An encoded string (s) is given, the task is to decode it. The pattern in which the strings are encoded is as follows. <count>[sub_str] ==> The substring 'sub_str' appears count times.Examples: Input : str[] = "1[b]"Output : bInput : str[] = "2[ab]"Output : ababInput : str[] = "2[a2[b]]"Output : abbabbInput : str[] = "3[b2[ca]]"Output :
15+ min read
Decrypt the encoded string with help of Matrix as per given encryption decryption technique
Given an encoded (or encrypted) string S of length N, an integer M. The task is to decrypt the encrypted string and print it. The encryption and decryption techniques are given as: Encryption: The original string is placed in a Matrix of M rows and N/M columns, such that the first character of the Original text or string is placed on the top-left c
6 min read
Decrypt message from given code by replacing all * with prefix values of encoded string
Given a string str of length of N that is in the encoded form with alphabets and * . The task is to find the string from which it was generated. The required string can be generated from the encoded string by replacing all the * with the prefix values of the encoded string. Examples: Input: str = ab*c*dOutput: "ababcababcd"Explanation: For the firs
4 min read
Decode a median string to the original string
Given a string s written in median form, change it back to the original string. The median letter in a string is the letter that is in the middle of the string. If the string’s length is even, the median letter is the left of the two middle letters. The given string is formed by writing down the median letter of the word, then deleting it and repea
7 min read
Decode a given string by removing duplicate occurrences
Given encoded string str such that 'a' is written 1 time, 'b' is written 2 times, and so on, until 'z' is written 26 times, the task is to decode the given string str. Note: The letter may contain spaces and punctuation marks, so don't ignore those. Examples: Input: str = "bbadddd"Output: badExplanation:As each letter is written corresponding to th
6 min read
Decode the String of special characters
Given an input string S of special characters where "@" represents "01", "#@" represents "111" and "##" represents "00". Decode the input string of special characters and print the number formed by decoding it. Examples: Input: S = "@#@##" Output: 60Explaination: @ represents "01" followed by #@ which represents "111", followed by ## which represen
9 min read
Decode a given pattern in two ways (Flipkart Interview Question)
A sender sends a binary string to a receiver meanwhile he encrypt the digits. You are given a encrypted form of string. Now, the receiver needs to decode the string, and while decoding there were 2 approaches. Let the encrypted binary string be P[] and actual string be S[]. First, receiver starts with first character as 0; S[0] = 0 // First decoded
8 min read
Decode the message from Data packets sent over the network
Over the network, messages are sent as data packets. Each data packet is a series of bytes (8bits = 1 byte). The task is to decode the data packet (str) of length N. The format of the data packet is as follows: The packet can be broken into 2 parts.The first byte represents a unique value, say K.The remaining bytes in the data packet represent the
6 min read
Decode the Secret Heist Code
Berlin and Professor are on a secret heist mission, They have a secret code that's the code which will signal Berlin to enter the building and initiate the heist. The plan is that the professor will write a word of random characters on his board. If removing characters from the word will give the secret code then it's time for Berlin to shine (init
13 min read
Edge Relaxation Property for Dijkstra’s Algorithm and Bellman Ford's Algorithm
In the field of graph theory, various shortest path algorithms especially Dijkstra’s algorithm and Bellmann-Ford’s algorithm repeatedly employ the use of the technique called Edge Relaxation. The idea of relaxation is the same in both algorithms and it is by understanding, the 'Relaxation property' we can fully grasp the working of the two algorith
4 min read
Difference between Greedy Algorithm and Divide and Conquer Algorithm
Greedy algorithm and divide and conquer algorithm are two common algorithmic paradigms used to solve problems. The main difference between them lies in their approach to solving problems. Greedy Algorithm:The greedy algorithm is an algorithmic paradigm that follows the problem-solving heuristic of making the locally optimal choice at each stage wit
3 min read
Algorithm Library | C++ Magicians STL Algorithm
For all those who aspire to excel in competitive programming, only having a knowledge about containers of STL is of less use till one is not aware what all STL has to offer. STL has an ocean of algorithms, for all < algorithm > library functions : Refer here.Some of the most used algorithms on vectors and most useful one's in Competitive Prog
7 min read
What is the stupidest sorting algorithm? (Worst Sorting Algorithm)
Bogo sort stands out as the undisputed champion of stupidity. Unlike other sorting algorithms that follow a structured approach, Bogo sort relies on sheer luck and randomness to achieve its goal. How Bogo Sort Works?Bogo sort operates on the following principle: Randomly shuffle the elements in the list.Check if the list is sorted.If the list is no
2 min read
Difference Between Dijkstra's Algorithm and A* Search Algorithm
Dijkstra's Algorithm and A* Algorithm are two of the most widely used techniques. Both are employed to the find the shortest path between the nodes in a graph but they have distinct differences in their approaches and applications. Understanding these differences is crucial for the selecting the appropriate algorithm for the given problem. What is
3 min read
Z algorithm (Linear time pattern searching Algorithm)
This algorithm efficiently locates all instances of a specific pattern within a text in linear time. If the length of the text is "n" and the length of the pattern is "m," then the total time taken is O(m + n), with a linear auxiliary space. It is worth noting that the time and auxiliary space of this algorithm is the same as the KMP algorithm, but
13 min read
Karatsuba algorithm for fast multiplication using Divide and Conquer algorithm
Given two binary strings that represent value of two integers, find the product of two strings. For example, if the first bit string is "1100" and second bit string is "1010", output should be 120. For simplicity, let the length of two strings be same and be n. A Naive Approach is to follow the process we study in school. One by one take all bits o
15+ min read
Remove all occurrences of a string t in string s using Boyer-Moore Algorithm
Given a string s and string t, the task is to remove all occurrences of a string t in a string s using the Boyer-Moore algorithm. Examples: Input: s = "ababaababa", t = "aba" Output: baab Input: s = "Geeksforgeeks", t = "eek"Output: Gsforgs Approach: This can be solved with the following idea: We initialize the bad character rule and then loop thro
10 min read
Remove all occurrences of string t in string s using KMP Algorithm
Given two strings s and t, the task is to remove all occurrences of t in s and return the modified string s, and you have to use the KMP algorithm to solve this. Examples: Input: s = "abcdefgabcabcabdefghabc", t = "abc"Output: "defgdefgh" Input: s = "aaabbbccc", t = "bbb"Output: "aaaccc" Approach: To solve the problem follow the below idea: We will
8 min read
Decrypt the String according to given algorithm
Given encrypted string str consisting of alphabets and numeric characters, the task is to decrypt the string and find the encrypted message. In order to decrypt the message, find every cluster of numeric characters representing a single alphabetic character which can be obtained by calculating the modulus of the number with 26 and the found value f
7 min read
Remove all occurrences of a word from a given string using Z-algorithm
Given two strings str of length N and word of length M, the task is to remove all the occurrences of the string word from the string str. Examples: Input: str = "asmGeeksasmasmForasmGeeks", word = "asm" Output: GeeksForGeeks Explanation: Removing "asm" from the string, str modifies str to GeeksForGeeks Input: str = "Z-kmalgorithmkmiskmkmkmhelpfulkm
15+ min read
Generate string by incrementing character of given string by number present at corresponding index of second string
Given two strings S[] and N[] of the same size, the task is to update string S[] by adding the digit of string N[] of respective indices. Examples: Input: S = "sun", N = "966"Output: bat Input: S = "apple", N = "12580"Output: brute Approach: The idea is to traverse the string S[] from left to right. Get the ASCII value of string N[] and add it to t
4 min read
String generated by typing given string in a keyboard having the button of given character faulty
Given a string str and a character ch, where the button of character ch is not working correctly. After pressing that key, it toggles the Caps Lock instead of that letter. The task is to print the string generated after typing str on such a faulty keyboard. Note: The string may contain both upper and lower case characters. Examples: Input: str = "T
8 min read
Given a string and an integer k, find the kth sub-string when all the sub-strings are sorted according to the given condition
Given a string str, its sub-strings are formed in such a way that all the sub-strings starting with the first character of the string will occur first in the sorted order of their lengths followed by all the sub-strings starting with the second character of the string in the sorted order of their lengths and so on. For example for the string abc, i
9 min read
Restore original String from given Encrypted String by the given operations
Given a string str and a positive integer N, the task is to reverse N characters and skip N characters until the end of the string to generate the encrypted message. Examples: Input: str = "ihTs suohld ebeas!y", K = 3 Output: This should be easy! Explanation: Reverse "ihT" -> "Thi" "s" remains the same "uoh" -> "hou", and so on. Input: str =
5 min read
Check if any permutation of a given string is lexicographically larger than the other given string
Given two strings str1 and str2 of same length N, the task is to check if there exists any permutation possible in any of the given strings, such that every character of one string is greater or equal to every character of the other string, at corresponding indices. Return true if permutation exists otherwise false. Example: Input: str1 = "adb", st
10 min read
An in-place algorithm for String Transformation
Given a string, move all even positioned elements to the end of the string. While moving elements, keep the relative order of all even positioned and odd positioned elements the same. For example, if the given string is "a1b2c3d4e5f6g7h8i9j1k2l3m4", convert it to "abcdefghijklm1234567891234" in-place and in O(n) time complexity. Below are the steps
15+ min read
Minimum number of subsequences required to convert one string to another using Greedy Algorithm
Given two strings A and B consists of lowercase letters, the task to find the minimum number of subsequence required to form A from B. If it is impossible to form, print -1.Examples: Input: A = "aacbe", B = "aceab" Output: 3 Explanation: The minimum number of subsequences required for creating A from B is "aa", "cb" and "e".Input: A = "geeks", B =
13 min read
Count of occurrences of each prefix in a string using modified KMP algorithm
Given a string S of size N, the task is to count the occurrences of all the prefixes of the given string S. Examples: Input: S = "AAAA" Output: A occurs 4 times AA occurs 3 times. AAA occurs 2 times. AAAA occurs 1 times. Explanation: Below is the illustration of all the prefix: Input: S = "ABACABA" Output: A occurs 4 times AB occurs 2 times ABA occ
15 min read
Article Tags :
Practice Tags :
Trending in News
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, check: true }), success:function(result) { jQuery.ajax({ url: writeApiUrl + 'suggestions/auth/' + `${post_id}/`, type: "GET", dataType: 'json', xhrFields: { withCredentials: true }, success: function (result) { $('.spinner-loading-overlay:eq(0)').remove(); var commentArray = result; if(commentArray === null || commentArray.length === 0) { // when no reason is availaible then user will redirected directly make the improvment. // call to api create-improvement-post $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id, }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); return; } var improvement_reason_html = ""; for(var comment of commentArray) { // loop creating improvement reason list markup var comment_id = comment['id']; var comment_text = comment['suggestion']; improvement_reason_html += `
${comment_text}
`; } $('.improvement-reasons_wrapper').html(improvement_reason_html); $('.improvement-bottom-btn').html("Create Improvement"); $('.improve-modal--improvement').hide(); $('.improvement-reason-modal').show(); }, error: function(e){ $('.spinner-loading-overlay:eq(0)').remove(); // stop loader when ajax failed; }, }); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ $('.improvement-reason-modal').hide(); } $('.improve-modal--improvement').show(); }); function loadScript(src, callback) { var script = document.createElement('script'); script.src = src; script.onload = callback; document.head.appendChild(script); } function suggestionCall() { var suggest_val = $.trim($("#suggestion-section-textarea").val()); var array_String= suggest_val.split(" ") var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(suggest_val.length <= 2000){ var payload = { "gfg_post_id" : `${post_id}`, "suggestion" : `
${suggest_val}
`, } if(!loginData || !loginData.isLoggedIn) // User is not logged in payload["g-recaptcha-token"] = gCaptchaToken jQuery.ajax({ type:'post', url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/", xhrFields: { withCredentials: true }, crossDomain: true, contentType:'application/json', data: JSON.stringify(payload), success:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-section-textarea').val(""); jQuery('.suggest-bottom-btn').css("display","none"); // Update the modal content const modalSection = document.querySelector('.suggestion-modal-section'); modalSection.innerHTML = `
Thank You!
Your suggestions are valuable to us.
You can now also contribute to the GeeksforGeeks community by creating improvement and help your fellow geeks.
`; }, error:function(data) { jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Something went wrong."); jQuery('#suggestion-modal-alert').show(); error_msg = true; } }); } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Minimum 5 Words and Maximum Character limit is 2000."); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Enter atleast four words !"); jQuery('#suggestion-modal-alert').show(); jQuery('#suggestion-section-textarea').focus(); error_msg = true; } if(error_msg){ setTimeout(() => { jQuery('#suggestion-section-textarea').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // load the captcha script and set the token loadScript('https://www.google.com/recaptcha/api.js?render=6LdMFNUZAAAAAIuRtzg0piOT-qXCbDF-iQiUi9KY',[], function() { setGoogleRecaptcha(); }); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.improvement-reason-modal').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { $('.spinner-loading-overlay:eq(0)').remove(); var result = e.responseJSON; if(result.detail.non_field_errors.length){ $('.improve-modal--improve-content .improve-modal--improve-content-modified').text(`${result.detail.non_field_errors}.`); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); $('.improvement-reason-modal').hide(); } }, }); });
Continue without supporting 😢