instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a code to find the longest substring of the given string with a length greater than or equal to 3 without repeating letters. Additionally, the code should return the starting and ending indices of the longest substring. The input string will only contain lowercase letters and its length will not exceed 10,000. Th... | codefeedback |
Find the first 20 numbers in the Fibonacci sequence, but the solution must be implemented using a recursive algorithm. | codefeedback |
Write a code to add two numbers given as input, where each number is a positive integer. The sum should be calculated using only bitwise operators (e.g. AND, OR, XOR, shift operators), and the time complexity should be O(log n), where n is the maximum number of bits required to represent the input numbers. Additionally... | codefeedback |
Write a Python function that takes a list of integers as a parameter and returns the sum of all the odd numbers in the list. The function should have a time complexity of O(n) and a space complexity of O(1). Additionally, the function should ignore negative numbers and only consider positive odd numbers.
Please note ... | codefeedback |
Given a string, remove all consecutive duplicates in the string. However, you are only allowed to use a constant amount of additional space. The original string must be modified in-place. Additionally, you must also handle cases where the consecutive duplicates occur in different cases, such as "aA" or "BB". The input ... | codefeedback |
Randomly rearrange the elements of the given array and ensure that no two adjacent elements have the same value. Additionally, each element in the rearranged array must be a prime number greater than 50.
nums = [12, 23, 34, 45] | codefeedback |
Given a string of characters, write a function in Python that returns only the lowercase characters. The function should ignore any punctuation or whitespace characters in the input string. Additionally, the function should not use any built-in Python functions or libraries that directly solve the problem (e.g., `str.i... | codefeedback |
Write a function in Python that takes a sentence as input and performs the following tasks:
1. Remove all spaces and punctuation marks.
2. Convert all letters to lowercase.
3. Check if the resulting string is a palindrome.
4. If the string is a palindrome, return True. Otherwise, return False.
The sentence should cont... | codefeedback |
Write a Python function that takes in a list of integers as input and returns a new list containing only the prime numbers in the input list, sorted in ascending order. However, the function should also remove any duplicates in the output list.
To further increase the difficulty, please optimize your solution to have ... | codefeedback |
Write a function in Python that takes two strings and returns a single string with the characters in alternating order, but only for the vowels in the strings. However, the vowels should be reversed in their original order. Additionally, the function should also remove any duplicate vowels from the output string.
For ... | codefeedback |
Suggest an efficient algorithm to generate a random number between a given range in JavaScript, where the lower bound and upper bound are provided as parameters. The algorithm should ensure that the generated random number is inclusive of both the lower and upper bounds. Additionally, the solution should have a time co... | codefeedback |
Write a function in Python that takes a string and splits it into a list of words. The string may contain punctuation marks, special characters, and emojis. However, the function should also handle multiple languages and scripts, such as Latin, Cyrillic, Arabic, Chinese, and Devanagari. Additionally, the function shoul... | codefeedback |
Write a Python program to format a given list of IP addresses in a specific way, where each IP address is displayed with its corresponding network address and subnet mask. The subnet mask should be represented in CIDR notation. Additionally, the program should validate the IP addresses to ensure they are valid and with... | codefeedback |
Write a Python function that generates a key-value pair for the given array. The key should be the sum of all the elements in the array, and the value should be a list of all the even numbers in the array, sorted in descending order. The function should also handle cases where the array contains non-integer elements. A... | codefeedback |
Write a function in Python that takes a list of strings and checks if they are all the same length and if they contain only lowercase alphabets. Additionally, the function should check if the strings contain at least one vowel and at least one consonant. Finally, the function should return the count of each distinct ch... | codefeedback |
Write a function that determines if a given substring is present in a string or not. The function should return the index at which the substring is found in the string. Additionally, if the substring is found multiple times in the string, the function should return a list of all the indices at which the substring occur... | codefeedback |
Write a function in Python that takes a list of integers and returns a new list containing only the prime numbers from the original list. The function should have a time complexity of O(n*(log(m))^2), where n is the length of the original list and m is the maximum value in the original list.
Note: The space complexity... | codefeedback |
Write a function in Python that takes a 2D array and returns the product of all elements in it. However, the array can contain elements of different data types, including integers, floating-point numbers, and strings. In the case of strings, the function should concatenate them instead of multiplying them. If there are... | codefeedback |
Write a function in Python that takes a list of strings and checks whether the list is empty or not. If the list is not empty, check whether all strings in the list are palindromes and have a length that is a prime number. Additionally, the function should raise a custom exception if any of the strings in the list cont... | codefeedback |
Given a paragraph, classify each word in the paragraph as a noun, verb, adjective, adverb, pronoun, conjunction, preposition, or interjection. Additionally, for each noun, verb, adjective, or adverb, determine its tense (past, present, future) and its degree (positive, comparative, superlative). The paragraph is: "The ... | codefeedback |
What data structure can be used to convert the following list into a dictionary, while ensuring that all keys are unique and all values are of the same data type, and also ensuring that the dictionary is sorted in descending order based on the length of the keys? The dictionary should also only include string keys and ... | codefeedback |
Generate a random password with at least 20 characters that contain both upper and lowercase letters, numbers, special characters, and at least one emoji. Additionally, the password should not contain any repeating characters. Implement the function `generate_password` which takes no arguments and returns the generated... | codefeedback |
Write a function that takes four arguments, a number, a list of integers, a list of target sums, and a boolean flag. The function should return all pairs of indices in the list where the sum of the corresponding elements equals one of the target sums. The function should return the pairs in ascending order of their fir... | codefeedback |
Write a code snippet to query the Internet Movie Database for the release dates and cast information of all movies directed by Christopher Nolan, ensuring that the code is asynchronous and uses a callback function to handle the response. Additionally, the code should handle any potential errors that may occur during th... | codefeedback |
Calculate the sum of all prime numbers in the given array that are multiples of the given number and are greater than or equal to a specified value.
numbers=[2, 3, 5, 7, 11, 13]
num=3
min_value=5 | codefeedback |
Develop a script in Perl to sort an array in descending order, without using any built-in sorting functions. The array should only contain unique integers between 1 and 100. Your script should also print the third largest element in the sorted array. Additionally, your script should handle arrays with a size up to 10^7... | codefeedback |
Write a JavaScript code snippet that appends the contents of one array to another array. The time complexity of your solution should be O(n), where n is the length of the second array. Additionally, the solution should not use any built-in array methods such as `concat`, `push`, or the spread operator (`...`).
Also, m... | codefeedback |
Count the number of words in a sentence that begin with a consonant, end with a vowel, have a length less than or equal to 10 characters, and contain at least one uppercase letter. | codefeedback |
Design a function which takes a parameter and returns the sum of the cubes of its digits. The parameter can be a positive integer or a string representing a positive integer. The function should handle both cases. The function should also handle negative integers as well as float numbers with decimal places. Additional... | codefeedback |
Write code to implement a double-ended priority queue in Python, where elements can be inserted and removed from both ends of the queue. The implementation should have an average time complexity of O(log n) for insertion and removal operations, and should use a space complexity of O(n).
In addition, modify the impleme... | codefeedback |
Convert the given English sentence into a Python function definition that takes a string as an input, reverses the string, and prints it on the screen. The function should also validate if the input is a valid string and raise a custom exception if it is not. Additionally, the function should implement a recursive appr... | codefeedback |
Implement a function in Python that prints a given string character by character, but ensure that the time complexity of your solution is O(n^2), where n is the length of the input string. Additionally, use only constant space complexity (i.e., O(1)). Your function should also handle strings that contain special charac... | codefeedback |
How can you generate a random array of 1,000,000 integers between -1,000,000 and 1,000,000, where each integer is unique and sorted in descending order? | codefeedback |
Write a MySQL query to display the name, total salary, and average salary of employees who earn more than the average salary of their department, have been employed for at least 2 years, and have a job title that starts with the letter 'S'. Additionally, sort the results in descending order based on the total salary.
... | codefeedback |
Write a code snippet that computes the sum of all prime numbers between 1 and 1,000, excluding the numbers 2 and 3. The code should use a recursive function and should be optimized to run in O(sqrt(n)) time complexity. | codefeedback |
Implement a nested for loop in Python that iterates over a 2-dimensional list and prints out each element in a specific format. Additionally, modify the code to add an extra condition that only prints out the elements if their sum is greater than a given threshold value. Furthermore, add a condition that skips the iter... | codefeedback |
Write a JavaScript function to generate a random strong password with length 12-15, and must contain at least two uppercase letters, two lowercase letters, two numbers, two special characters, and must not contain any repeated characters. | codefeedback |
Write a Python script that performs multiple linear regression to predict a response variable, considering at least ten predictor variables and handling any missing data appropriately. Additionally, implement a k-fold cross-validation technique with k=5 to evaluate the performance of the model. The script should also i... | codefeedback |
Please write a script that deletes elements that appear three or more times consecutively in a list. The script should meet the following requirements:
1. The script should handle lists of any length, including empty lists.
2. The script should handle lists containing elements of any data type.
3. The script should ha... | codefeedback |
Write a code snippet that prints out the number of times each vowel appears in a given string. The input string may contain uppercase and lowercase letters, numbers, and special characters. If the string is empty or does not contain any vowels, print "No vowels found".
Example:
Input: "H3ll0 w0rld!"
Output:
a: 0
e: 0
... | codefeedback |
What is the maximum depth of a binary tree of size n if the binary tree is balanced and the nodes are stored in an array? Please provide a step-by-step approach to calculate the maximum depth.
1. Initialize a variable maxDepth to 0.
2. Calculate the height of the binary tree using the formula: height = log2(n+1) - 1. ... | codefeedback |
Implement a function in your preferred programming language that takes in a list of strings and returns the most frequent string(s) in the list. In the case of a tie, return all the strings with the highest frequency.
Additionally, the function should handle strings that contain alphanumeric characters, including spec... | codefeedback |
Write a Python function to convert a dictionary into a list of tuples. The dictionary may contain nested dictionaries and lists as values. The output list should contain tuples where each tuple represents a key-value pair from the dictionary. If a nested dictionary or list is encountered, it should be flattened and rep... | codefeedback |
Design a function for creating an array with n elements, where each element is the sum of its five preceding elements. The first five elements of the array should be 0, 1, 1, 2, and 4. The time complexity of the function should be O(n) and the space complexity should be O(1). | codefeedback |
Create a matrix of ones with shape 10x10 using the NumPy library. The matrix should have all even numbers except for the first and last rows, which should have all odd numbers. | codefeedback |
Design an algorithm to check for missing numbers in an array of size n, where the array contains both positive and negative integers, and the missing numbers can be either positive or negative. Additionally, the algorithm should have a time complexity of O(n), but with an additional space complexity requirement of O(1)... | codefeedback |
Create a function that takes an integer as input and returns a list of prime numbers less than that integer. The function should also check if the input is a positive integer greater than 1, and raise a custom exception if it is not.
The function should have a time complexity of O(n^1.5) or better, and a space complex... | codefeedback |
Implement a class called "Vehicle" in an object-oriented programming language of your choice. The class should have the following attributes:
- make (string)
- model (string)
- year (integer)
- color (string)
- speed (float)
The class should also have the following methods:
- accelerate: increases the speed of the veh... | codefeedback |
Write a C program to implement a scientific calculator that can perform addition, subtraction, multiplication, division, square root, exponentiation, and logarithm operations on two numbers. The program should be able to handle floating-point numbers and display the result up to a specified number of decimal places. Ad... | codefeedback |
Write a function that takes a list as a parameter and returns only the unique elements in the given list. You may not use any built-in functions or libraries to accomplish this task. Additionally, your solution should have a time complexity of O(nlogn), where n is the length of the input list.
Please note that the lis... | codefeedback |
Write a program that takes an input array of integers and prints out every fifth element in the array. However, if the fifth element is divisible by 2, the program should print out the element multiplied by 3 instead. Additionally, if the fifth element is divisible by 3, the program should skip printing that element al... | codefeedback |
Create an algorithm to find the longest substring of a given string with distinct characters, where the substring must also contain at least one uppercase letter, one special character, and one digit. The length of the substring must be greater than or equal to 5 characters and less than or equal to half the length of ... | codefeedback |
Create a C++ program that finds the kth most common element in the given input array. The value of k will be provided as an input to the program. If there is a tie for the kth most common element, output all the tied elements in descending order. Additionally, the program should also find and output the (k+1)th most co... | codefeedback |
Create a function to perform insertion sorting on a given list of integers in descending order.
# Revised Code #
def insertion_sort_descending(lst):
for i in range(1, len(lst)):
key = lst[i]
j = i-1
while j >= 0 and lst[j] > key:
lst[j+1] = lst[j]
j -= 1
lst[... | codefeedback |
Write a PHP program to convert a string to a URL safe string, ensuring that special characters are properly encoded. The program should also remove any duplicate characters in the input string before encoding it. Additionally, the program should be able to handle multiple encoding schemes such as percent encoding, HTML... | codefeedback |
Write a code to print all numbers between a given range (inclusive) in the format shown below, but skip any numbers that are divisible by both 3 and 5. Additionally, the program should count and display the total number of skipped numbers. However, the program should also skip any numbers that are divisible by both 2 a... | codefeedback |
Convert a given array of numbers into a square matrix, ensuring that the sum of each row, column, and diagonal is equal to a given target number. Given array = [1, 2, 3, 4], target number = 10.
Additionally, provide a constraint that the elements in the top left to bottom right diagonal must be strictly increasing in ... | codefeedback |
Create a responsive web page with the headline "Welcome to Python programming" that uses a custom font and a background image. The custom font should have a gradient color effect with a smooth transition between colors. The background image should have a parallax scrolling effect, where the image moves at a different s... | codefeedback |
Write a Java program for binary search that operates on a sorted array of integers. The program should take an input array and a target integer as parameters and return the index of the target integer in the array. If the target integer is not found in the array, the program should return -1. The program should have a ... | codefeedback |
Rewrite this program to use an embedded loop instead of recursion. Additionally, the program should now include a constraint that the solution must have a time complexity of O(n) and a space complexity of O(1). The solution must also handle the case when the input is a negative integer and return the corresponding resu... | codefeedback |
Using JavaScript, create an algorithm to check if an array of numbers is sorted in ascending order and does not contain any duplicate elements, without using any built-in array methods such as sort() or reverse(). Additionally, your algorithm should have a time complexity of O(nlogn), where n is the length of the array... | codefeedback |
Develop a function to calculate the total amount of the order for an online store, taking into account discounts and taxes. The online store sells five different products, ProductA, ProductB, ProductC, ProductD, and ProductE, with different prices and discounts. The prices and discounts for each product are as follows:... | codefeedback |
Create a SQL table with the following schema: id (integer), name (string), city (string), and email (string). The email field should only accept valid email addresses in the format "example@example.com". Additionally, implement a constraint that ensures that the email domain must be one of the following: "gmail.com", "... | codefeedback |
Design an algorithm that prints all the permutations of a given string, but without using recursion. Additionally, the algorithm should have a time complexity of O(n!) and should not use any built-in functions or libraries for generating permutations. The algorithm should also utilize multi-threading to increase effici... | codefeedback |
Write a code to send a message "Hello World!" using the Twilio API. The message must also include the current date and time in UTC format. Additionally, the code should handle and log any errors that may occur during the sending process. The code should be implemented in a multi-threaded manner, allowing for concurrent... | codefeedback |
You are given a string and you want to sort all characters in the string alphabetically in descending order. However, you are not allowed to use any built-in sorting functions or libraries. You must implement your own sorting algorithm to solve this problem.
Additionally, you must handle special characters and numbers... | codefeedback |
Construct a SQL query to get the sum of all the purchased items from a given table, excluding any items with a quantity less than or equal to 0, and sort the result in descending order of the purchase price. Additionally, group the result by the purchase date and display the total quantity of each purchased item. The q... | codefeedback |
Convert the following floating-point number to its binary representation, using the IEEE 754 standard.
Number: -256.625
1. Explain the IEEE 754 standard for representing floating-point numbers in binary format, including the different formats for single precision and double precision.
2. Discuss the different compone... | codefeedback |
Create a web application that allows users to manage a database of employee information. The application should have a login system where users can create an account and login to access the employee database. Each user should only be able to see and edit the employee information that they have added.
The application ... | codefeedback |
Write a function to implement the sequential search algorithm to find the maximum and minimum elements in an array. The function should return both the maximum and minimum elements in the array.
The input array, arr, will contain n elements, where 1 <= n <= 10^9. Each element in the array will be an integer between -1... | codefeedback |
Given a matrix of size NxM, make a code that prints the transpose of the matrix. The matrix can contain integers, decimals, or characters.
Additional Constraints:
- The code should have a time complexity of O(N*M).
- The code should not use any built-in functions or libraries for transposing the matrix.
- The code sho... | codefeedback |
Implement an efficient algorithm that takes as input two positive integers and calculates their greatest common factor. The algorithm should run in O(sqrt(min(a, b))) time complexity, where a and b are the input integers. Additionally, the algorithm should not use any built-in functions or libraries for calculating the... | codefeedback |
Write a function that uses regular expressions to match two strings. The first string must be a combination of lowercase and uppercase letters, and the second string must be a combination of lowercase letters, uppercase letters, digits, and special characters. The second string must also be a palindrome and contain at ... | codefeedback |
Write a function in Python that takes a list of positive integers as input and returns a new list with the numbers sorted in descending order using the Radix Sort algorithm.
Note: Do not use any built-in sorting functions or methods. | codefeedback |
Write a function that prompts the user to input the length of an array (length should be between 1 and 100, inclusive) and then the values for each element in the array (values should be integers between -100 and 100, inclusive). The function should also prompt the user to input the index of the desired value (index sh... | codefeedback |
Create two sets and find the intersection between them. The intersection should only include numbers that are divisible by 3, less than 5, have a prime digit in them, and are not multiples of 2 or 5.
Set A: [1, 2, 3, 4, 5, 6, 7]
Set B: [2, 4, 6, 8, 10, 11, 12] | codefeedback |
Write an SQL Query to print a list of all employees who have a higher salary than their managers, considering that each employee can have multiple managers and each manager can have multiple employees. The query should also include the department name of each employee. In addition, the query should exclude employees wh... | codefeedback |
Write a MIPS code that adds two numbers and stores the result in a given memory address, but you are not allowed to use the add instruction. You can only use bitwise operations, conditional statements, and a maximum of 5 lines of code to perform the addition. The two numbers to be added are stored in the registers $t1 ... | codefeedback |
Create a function to format a given phone number in the format "(123) 456-7890" and output a string with the canonical format of "+1-123-456-7890". The function should also handle cases where the phone number is passed in as a string or with additional characters such as hyphens or dots. Additionally, the function shou... | codefeedback |
Write Swift code to find the largest prime palindrome number less than 1 million. | codefeedback |
Create a function that parses a valid IP address from a string and returns the address string without delimiters and periods. However, the function should also handle cases where the input string may contain multiple IP addresses separated by commas. In such cases, the function should return a list of the parsed IP add... | codefeedback |
Using Pandas, count how many rows have a value of "United States" in the "Country" column, a value of "California" in the "State" column, and a value of "Female" in the "Gender" column. Additionally, exclude any rows where the value in the "Age" column is greater than 30. Finally, calculate the average of the values in... | codefeedback |
Given a singly linked list, reverse it in place. The linked list can contain duplicates. Additionally, you are not allowed to use any extra data structures, recursion, or the built-in reverse function in your solution. Ensure that your solution has a time complexity of O(n), where n is the number of nodes in the linked... | codefeedback |
Using the requests library, post a JSON object to a specified URL. However, the URL provided is incorrect and needs to be fixed in order for the code to work properly. The URL contains a randomly generated string of alphanumeric characters and must be fixed by replacing a single character at a randomly chosen position ... | codefeedback |
Generate a SQL query to retrieve all records from the USERS table where the gender is 'Male', the age is greater than 30, the user's name starts with the letter 'J', and the user's last name ends with the letter 'n'. | codefeedback |
Create a custom implementation of a Hashtable in Java to store a list of key-value pairs. The keys must be unique and of type String, and the values must be of type Integer. The Hashtable should have a maximum size of 100 and should not allow any null values to be added. Additionally, implement the following methods:
... | codefeedback |
Write a JavaScript code to print out the multiplication table of a given number, but exclude any multiples that are divisible by 3 or 7. Additionally, if the given number is a prime number, exclude any multiples that are divisible by 2 or 5.
#Example#
Input:
num = 7
Output:
7 x 1 = 7
7 x 2 = 14
7 x 4 = 28
7 x 8 = 56... | codefeedback |
Please write a PHP function to delete a record from a database table. The table name is "details" and the key to identify the record is "user_id". The value of the "user_id" is 10.
Requirements:
1. Before deleting the record, check if the record with the specified user_id exists in the table. If it doesn't exist, disp... | codefeedback |
Make an array containing all prime numbers that are greater than 1000 and less than 2000. The final array should be sorted in ascending order and have no repeated elements. | codefeedback |
Use the requests library to make an API call to the endpoint "https://api.example.com/v1/users" with a POST request, passing a JSON payload containing a user's name, email, and password. However, the API requires authentication using an API key which needs to be included in the request headers. The API key can be obtai... | codefeedback |
Given an array of positive integers, remove all the duplicates in-place and sort the remaining unique elements in descending order. The function should modify the original array in-place and return the new length of the array. Additionally, the solution should be implemented in constant space complexity, meaning that t... | codefeedback |
Make a function in Python which calculates the covariance between two given lists.
However, the lists may contain missing values (represented by None) and the length of the two lists may not be the same. Additionally, the function should handle cases where both lists are empty or contain only missing values, and retur... | codefeedback |
Modify the following program to print the number of occurrences of each non-alphanumeric character in string s, excluding any whitespace characters and ignoring the case sensitivity.
String s = "Hello World!" | codefeedback |
Create a loop to print the prime numbers in reverse order from 10^6 to 1. | codefeedback |
Generate a random array of size n in Python. The array should only contain unique elements and should be sorted in ascending order. Additionally, the array should have a time complexity of O(n) and a space complexity of O(1). Size of array: 1000 | codefeedback |
Convert the given string to an array of characters in Java, but exclude any vowels, special characters, and whitespaces from the array. Also, convert all uppercase characters to lowercase before sorting the array in descending order based on the ASCII values of the characters. Return the final sorted array as the outpu... | codefeedback |
Create a class in Java for a rectangle shape with length and breadth as attributes. The rectangle should also have a method to calculate its area and perimeter. Additionally, the rectangle's length and breadth should be prime numbers, and the maximum length or breadth should not exceed 1000.
Now, modify the rectangle... | codefeedback |
Construct a SQL query to group students by the grade they got, calculate the average score, and include only the students who have a score higher than 90. Additionally, order the groups by the average score in descending order.
To increase the difficulty, add a requirement to exclude any students who have a grade of ... | codefeedback |
Create a method in JavaScript that takes a comma-separated list of values as an argument and returns an array containing those values. However, the method should also handle cases where there are leading or trailing spaces before or after each value in the list. Additionally, if any value in the list is a string enclos... | codefeedback |
You are given a list of integers and you need to implement a recursive function that checks if the list is sorted in non-decreasing order. The function should return True if the list is sorted correctly, and False otherwise. The function should handle edge cases, such as an empty list and a list with duplicate elements... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.